-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Restrict AST nodes according to string length #7785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you verified that the extraction query now works on the relevant database? When we concatenate the body tokens from each AST node together to form the full body token feature, we could still potentially reach the length limit.
From a brief dive into the code, the string limit may be 1,048,576 bytes. Therefore a safer limit might be 1,048,576/(max num ast nodes in body feature) = 1,048,576/1024 = 1,024 bytes / characters. We'd need to subtract one from that for the space separator, so perhaps a 1000 character limit is sensible? I think it probably still needs testing though.
|
Sorry this is a draft, and I shouldn't have asked you to take a look yet. No this does not solve the problem at all. The difficulty, seems to be, that the size restriction in Perhaps I need to implement a separate predicate that somehow counts the total number of characters in all the |
|
@henrymercer I've tested that this change now fixes the problem. However, it may have other knock-ons that I don't understand. Ready for review now. |
...ntal/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/FunctionBodyFeatures.qll
Outdated
Show resolved
Hide resolved
...ntal/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/FunctionBodyFeatures.qll
Show resolved
Hide resolved
| // Performance optimization: If a function has more than getMaxChars() characters in its body subtokens, | ||
| // then featurize it as absent. | ||
| function = getFeaturizableFunction(function) and | ||
| result = strictconcat(Location l, string token | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the behaviour of the function body features potentially quite considerably. The AST node limit was a factor that noticeably affected end-to-end performance, and using a different restriction here could have important implications on the runtime of the ML-powered queries.
We need to validate the runtime implications of this change before we merge it. Furthermore, we should either (a) stick with the removal of the AST node limit, train a new model on the new features and run an end-to-end evaluation, or (b) reintrodue the AST node limit, so the feature values should not change considerably.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Will reinstate the AST node limit
- Will collect timing measures
- Will run end-to-end evaluation
This comment was marked as outdated.
This comment was marked as outdated.
|
End-to-end results are here:
This PR should have 2 effects:
More detective work is needed to understand the cause of the increase in recoverable alerts in the end-to-end metrics. |
|
Some timing tests. Conclusion: this change probably has no effect on query execution time. N.B. Before each run I brutally cleared database caches and pre-compiled the queries.
|
The difference is due to an improvement in modeling unrelated to this PR. See https://github.com/github/ml-ql-adaptive-threat-modeling-backend/pull/1185 |
|
@henrymercer I've reinstated the AST node limit, collect timing measures (no effect) and performed end-to-end evaluation (no effect). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks good overall. Minor suggestions to improve the code, then let's get this in.
...ntal/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/FunctionBodyFeatures.qll
Show resolved
Hide resolved
...ntal/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/FunctionBodyFeatures.qll
Outdated
Show resolved
Hide resolved
...ntal/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/FunctionBodyFeatures.qll
Outdated
Show resolved
Hide resolved
...ntal/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/FunctionBodyFeatures.qll
Show resolved
Hide resolved
…ntal/adaptivethreatmodeling/FunctionBodyFeatures.qll Co-authored-by: Henry Mercer <henrymercer@github.com>
...ntal/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/FunctionBodyFeatures.qll
Outdated
Show resolved
Hide resolved
…ntal/adaptivethreatmodeling/FunctionBodyFeatures.qll Co-authored-by: Henry Mercer <henrymercer@github.com>
Fix for the catastrophic error identified in https://github.com/github/ml-ql-adaptive-threat-modeling/issues/1618
The catastrophic error is
CatastrophicError "String too long (5395415 characters)", which occurs when we tokenize the string associated with theASTNode. I've added a restriction to throw away strings that are longer than 1,000,000 characters before we attempt to tokenize them.