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 level too deep when decrypting objects #209

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cgunther
Copy link
Contributor

As demonstrated in the following file, a stack level too deep error seems possible in the ObjectHash#decrypt method
https://www.dropbox.com/s/4lvx469c580iuiv/pdf-reader%20decrypt%20stack%20overflow.pdf?dl=0

The stacktrace I got trying to access the first page (pages.first) was:

SystemStackError: stack level too deep
  from pdf-reader/lib/pdf/reader/object_hash.rb:318:in `decrypt'
  from pdf-reader/lib/pdf/reader/object_hash.rb:317:in `block in decrypt'
  from pdf-reader/lib/pdf/reader/object_hash.rb:317:in `each'
  from pdf-reader/lib/pdf/reader/object_hash.rb:317:in `map'
  from pdf-reader/lib/pdf/reader/object_hash.rb:317:in `decrypt'
  from pdf-reader/lib/pdf/reader/object_hash.rb:317:in `block in decrypt'
  from pdf-reader/lib/pdf/reader/object_hash.rb:317:in `each'
  from pdf-reader/lib/pdf/reader/object_hash.rb:317:in `map'
  from pdf-reader/lib/pdf/reader/object_hash.rb:317:in `decrypt'
  from pdf-reader/lib/pdf/reader/object_hash.rb:84:in `[]'
  from pdf-reader/lib/pdf/reader/object_hash.rb:98:in `object'
  from pdf-reader/lib/pdf/reader/object_hash.rb:343:in `get_page_objects'
  from pdf-reader/lib/pdf/reader/object_hash.rb:348:in `block in get_page_objects'
  from pdf-reader/lib/pdf/reader/object_hash.rb:348:in `map'
  from pdf-reader/lib/pdf/reader/object_hash.rb:348:in `get_page_objects'
  from pdf-reader/lib/pdf/reader/object_hash.rb:243:in `page_references'
... 4 levels...
  from pdf-reader/lib/pdf/reader.rb:176:in `map'
  from pdf-reader/lib/pdf/reader.rb:176:in `pages'
  from (irb):1

This error was seen on v2.0.0 as well as master.

This PR probably shouldn't be merged directly. My intention was to demonstrate the error and take a basic pass at fixing it, but I'm not really sure what the #decrypt method does or what it's arguments represent. I mainly looked at #198 and tried to apply similar changes. I'm not sure how to come up with a minimal test case as you did in #198 to add to the test suite, or what exactly to test other than "doesn't error".

Thanks for pdf-reader!

Base automatically changed from master to main January 30, 2021 22:38
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