yob / pdf-reader

The PDF::Reader library implements a PDF parser conforming as much as possible to the PDF specification from Adobe.
MIT License
1.81k stars 271 forks source link

Error: undefined method '[]=' for nil:NilClass #346

Closed pbalaban closed 3 years ago

pbalaban commented 3 years ago

First of all, thanks for creating this awesome gem! I'm start searching inside PDF files and it helps me a lot.

Some of PDF files can not be processed correctly and the lib raises undefined method '[]=' for nil:NilClass error. The issue is reproducible on version 2.4.2 with the attached file and the code below:

[3] pry(main)> PDF::Reader.new("1397476_1_A.pdf").pages.first.text
NoMethodError: undefined method `[]=' for nil:NilClass
from /home/peter/.rvm/gems/ruby-2.6.3@lytics/gems/pdf-reader-2.4.2/lib/pdf/reader/page_layout.rb:121:in `local_string_insert'

I tried to downgrade the version and it seems that issue appears somewhere between 2.0.0 and 2.1.0

yob commented 3 years ago

Thanks for the clear report and sample file - I've added a fix and spec in #347.