Repository navigation
ROB: Guard ArrayObject.read_from_stream against uncaught RecursionError #4430
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -807,6 +807,17 @@ def test_array_object__read_from_stream__maximum_element_count() -> None: | |
| ArrayObject.read_from_stream(BytesIO(data), pdf=pdf) # type: ignore[arg-type] | ||
|
|
||
|
|
||
| def test_array_object__read_from_stream__deeply_nested_array_raises_pdfreaderror() -> None: | ||
| # A single array nested thousands of levels deep drives recursion depth, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not see how this comment provides benefits, especially as inline comment instead of docstring. |
||
| # not element count, so array_maximum_element_count never engages. | ||
| # Previously this raised an uncaught RecursionError instead of PdfReadError. | ||
| pdf = ReaderDummy() | ||
| depth = 5000 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need a depth of 5000 to trigger an issue which occurs with exceeding |
||
| data = b"[" * depth + b"]" * depth | ||
| with pytest.raises(PdfReadError, match=r"^Error reading PDF file\.$"): | ||
| ArrayObject.read_from_stream(BytesIO(data), pdf=pdf) # type: ignore[arg-type] | ||
|
|
||
|
|
||
| def test_dictionary_object__read_from_stream__token_limit() -> None: | ||
| pdf = ReaderDummy() | ||
| data = b"<< /Key1 << /Key2 << /Key3 << /Key4 << /SomeName 42 >> >> >> >> /Key5 13 >>" | ||
|
|
||
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.
Why do we need this large comment? The referenced case does not have one and nesting triggering recursion errors in such a scenario should be obvious and - if required - derivable from the corresponding PR once merged.