Bug 18364 - OutlineItem::readItemList blindly follows loops in outlines definitions
Summary: OutlineItem::readItemList blindly follows loops in outlines definitions
Status: RESOLVED FIXED
Alias: None
Product: poppler
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: poppler-bugs
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-03 18:57 UTC by Nick Jones
Modified: 2009-03-02 15:58 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
add hash check for outlines section numbers (1.28 KB, patch)
2008-11-03 18:57 UTC, Nick Jones
Details | Splinter Review
Add a lookup table for ref numbers already found in OutlineItem::readItemList (1.29 KB, patch)
2009-03-02 00:24 UTC, Nick Jones
Details | Splinter Review
Lookup table for reference numbers shared between Catalog and Outline (5.56 KB, patch)
2009-03-02 00:25 UTC, Nick Jones
Details | Splinter Review

Description Nick Jones 2008-11-03 18:57:10 UTC
Created attachment 20027 [details] [review]
add hash check for outlines section numbers

If the definition of an outlines section in a document is broken and /Next references contain a loop, libpoppler will follow this blindly and become stuck in a loop of its own.

The broken documents I found had sections arranged like:
24 /First 25 ... /Type/Outlines
25 /Next 51 ...
27 /Next 28 ...
28 /Next 52 ...
29 /Next 27 ...
30 /Next 29 ...
...
50 /Next 49 ...
51 /Next 50 ...
52 /Next 51 ...

I assume that the same bug could be triggered with just two Outlines sections.

Attached is a patch that fixes this issue, but I have no experience with the workflow and coding practises of the poppler project, so it may not suit the authors.

This issue applies to v0.8.7 and earlier.  The patch is valid for this version and also applies cleanly to 0.5.9

The patch works by adding a hash of outline section numbers visited.  If a number appears again, the loop is exited.
Comment 1 Albert Astals Cid 2008-11-04 10:52:18 UTC
I was waiting until someone decided to create a CVE or something due to this, congratulations for being the one in the outside to notice and care :-)

I'd like you to suggest a patch based on the same approach used in Catalog::readPageTree and alreadyRead

It's probably more memory intensive but does not slow down things as much as yours does and given there's already one place where such construction is used memory usage is not a problem.
Comment 2 Nick Jones 2009-03-02 00:22:31 UTC
Excuse my lazyness in getting back...

I redid the original patch using your suggested method, against the sources for v0.10.4

It will be attached as : outlineitems_alreadyread.patch

Having already made the first patch, I re-read your previous comment and noted the part: 'already one place where such construction is used' so I redid the patch once again, with a alreadyRead buffer shared between the Catalog and Outline objects, in case that is what you were hinting.

It is a bit messy passing the buffer around though, I contemplated putting it in the XRef structure, but it seems this structure has not changed in many versions of poppler, so I assumed it is required to remain unchanged?

Anyhow, I hope one of these patches is of use.
Comment 3 Nick Jones 2009-03-02 00:24:23 UTC
Created attachment 23431 [details] [review]
Add a lookup table for ref numbers already found in OutlineItem::readItemList
Comment 4 Nick Jones 2009-03-02 00:25:03 UTC
Created attachment 23432 [details] [review]
Lookup table for reference numbers shared between Catalog and Outline
Comment 5 Albert Astals Cid 2009-03-02 15:58:01 UTC
I've commited patch from comment #3, thanks a lot for the work :-)


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.