feat: resolving invalid parsing causing stack overflow #280
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is intended as resolution to #278 and #279.
Both issues report test files that when parsed cause a stack overflow.
The stack overflow is set up by providing many multiple array start char -
[
- or dict start chars -<<
. Each such start triggers a new recursion level at the object parser looking to parse the items of the array or dict. when in themselves they are arrays or dicts (by having that starter token) there's another level...and another...and another.I put a max depth, of either dicts or arrays parsing at 100. This includes resolving cases of such sequences that intermingle array and dict start like
<<[<<[<<[[[[<<[<<<<[
. If there's a depth of 100 of either dicts or arrays including each other the code will halt parsing with a failure and return. This limit should take any valid PDF and parse it well, and stop naughty PDFs.