ROB: guard empty link destination arrays during page transfer#3896
ROB: guard empty link destination arrays during page transfer#3896metsw24-max wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3896 +/- ##
==========================================
+ Coverage 97.83% 97.86% +0.03%
==========================================
Files 55 57 +2
Lines 10609 10742 +133
Branches 1985 2009 +24
==========================================
+ Hits 10379 10513 +134
Misses 127 127
+ Partials 103 102 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| outlist.append(ano.clone(self).indirect_reference) | ||
| else: | ||
| d = cast("ArrayObject", d) | ||
| if not isinstance(d, list) or not d: |
There was a problem hiding this comment.
If we check for an ArrayObject here, could we avoid the explicit casting?
There was a problem hiding this comment.
Good point. Switched both branches to check isinstance(d, ArrayObject) directly, so the explicit cast is gone and mypy still narrows fine.
| outlist.append(ano.clone(self).indirect_reference) | ||
| else: | ||
| d = cast("ArrayObject", d) | ||
| if not isinstance(d, list) or not d: |
There was a problem hiding this comment.
Same change here, checks for ArrayObject directly now.
| writer.write(output_stream) | ||
|
|
||
|
|
||
| def _reader_with_link_annotation(annotation: DictionaryObject) -> PdfReader: |
There was a problem hiding this comment.
Why do we need an external helper if it is only used in one other function?
There was a problem hiding this comment.
Fair, it was only used once. Inlined it into the test.
| "annotation", | ||
| [ | ||
| # Empty /Dest array. | ||
| DictionaryObject({ |
There was a problem hiding this comment.
Please provide meaningful IDs.
There was a problem hiding this comment.
Added ids: empty-dest-array, empty-goto-action-dest, non-array-dest.
Signed-off-by: Sayed Kaif <metsw24@gmail.com>
|
Pushed the review changes: both branches now check |
|
any update? |
|
As already mentioned in your three other PRs, I recommend you to have a look at #3900. Until then, pinging for updates might have the effect of moving it to the end of my queue and even further delaying it. |
Empty link destination arrays crash page transfer
A
/Linkannotation whose/Dest(or/GoToaction/D) is an empty array makes page transfer read the target page fromd[0]with no length check, soappend()/merge()raiseIndexErrorin_insert_filtered_annotations, andadd_page()followed bywrite()raises it fromDirectReferenceLink.find_referenced_pagevia_resolve_links; a non-array/DesttripsTypeErrorlikewise. Both sites now skip a destination that is not a non-empty array, matching the existing drop-when-unresolvable handling and theNonepath already present in_resolve_links.Repro: