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

Fix RangeError (1..0 out of range) #495

Closed Cashaca closed 2 years ago

Cashaca commented 2 years ago

I have Pdf documents where the needle length is 0 and this generates a RangeError (1..0 out of range) without a check for needle.length > 0

yob commented 2 years ago

Thanks for flagging this.

RangeError (1..0 out of range)

If we're calling Range.new(1,0) and the 0 is calculated as 1+ needle.length - 1 (index + needle.length - 1), then it seems like pdf-reader is trying to render an empty string to the page, which is weird. Maybe we can avoid calling local_string_insert() all together in that case?

Is it possible to provide one of the PDFs to me via email (details are on my website: https://yob.id.au) so I can take a closer look at what's happening? I can commit to not sharing the file, but I understand if it's still not possible.

yob commented 2 years ago

Fixed by #496 . Thanks for reporting the issue ❤️