Repository navigation
Conversation
Prevents possible stack overflow with very large expressions or expressions that have a large number of parens or pluses. Changes the tokenizer to use streams. Adds a cap to the number of tokens - currently, 1,000. Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
pmonks
left a comment
There was a problem hiding this comment.
LGTM!
Just out of interest, what's the largest / most complex SPDX expression you've encountered? Just curious what precipitated this as much as anything.
I've run into some really large generated expressions where the tool rolls up all discovered licenses for a package as "AND's", pretty comfortably less than the 1,000 tokens, however. The issue was submitted from based on a security review of the code. |
|
A situation where expression canonicalisation might help! |
|
Thanks Gary, this looks right. Replacing the recursive processPreToken with the stream split closes the tokenizer sink, and the MAX_TOKENS cap on both parseLicenseExpression and parseLicenseExpressionCompatV2 bounds the parser recursion before it can overflow, so callers now get a catchable LicenseParserException instead of the fatal error. I appreciate the quick fix and the tests. |
Prevents possible stack overflow with very large expressions or
expressions that have a large number of parens or pluses.
Changes the tokenizer to use streams.
Adds a cap to the number of tokens - currently, 1,000.