Skip to content
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

Avoid stack overflow #198

Merged
merged 4 commits into from
Feb 12, 2017
Merged

Avoid stack overflow #198

merged 4 commits into from
Feb 12, 2017

Conversation

yob
Copy link
Owner

@yob yob commented Feb 12, 2017

This is an alternative solution to #195. This version is messier and less elegant, but more correct. Assuming it builds green, I'm inclined to merge this one instead and refactor later with the safety of the new specs.

deref! was added in 9c520b6 and attempts to return a deep object graph that contains no PDF::Reader::Reference objects and can be walked without risk of needing to refer back to the associated ObjectHash instance.

This change resolves a recursion bug that can occur in real world files

yob added 4 commits February 7, 2017 22:50
This single page PDF has a Form XObject in its Resources dict. The Form
XObject has its own Resources dict, which has an XObject pointing to
itself.

Nested XObjects are fine, but not recursive ones.

This is a simpler file that demonstrates an issue originally found in
the PDF provided at [1]

[1] #94 (comment)
Given an input collection like so:

    a = [1, b]
    b = [2, c]
    c = [3, a]

ObjectHash#deref!(a) should return the correct value without falling
into an endless loop that overflows the stack.

Similar data structures are possible with Hash's and Streams, so we have
to jump through hoops for them too.
The seen arg is purely for internal use, and exists to avoid endless
loops in the recursion. Arranging the methods this way means the arg
wont be visible in the public API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant