Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

undefined method `match' for nil:NilClass when passing file of 0 Bytes #69

Closed
zedtux opened this Issue · 3 comments

2 participants

@zedtux

Hello,

When using a PDF file of size 0 Bytes, we got the following error:

undefined method `match' for nil:NilClass

The error is raise from object_hash.rb @ line 326.

Find the stack trace:

undefined method `match' for nil:NilClass
/srv/fundlook_testing/shared/bundle/ruby/1.8/gems/pdf-reader-1.0.0/lib/pdf/reader/object_hash.rb:326:in `read_version'
/srv/fundlook_testing/shared/bundle/ruby/1.8/gems/pdf-reader-1.0.0/lib/pdf/reader/object_hash.rb:44:in `initialize'
/srv/fundlook_testing/shared/bundle/ruby/1.8/gems/pdf-reader-1.0.0/lib/pdf/reader.rb:116:in `new'
/srv/fundlook_testing/shared/bundle/ruby/1.8/gems/pdf-reader-1.0.0/lib/pdf/reader.rb:116:in `initialize'
....
@zedtux

I changed the initialize of ObjectHash like this:

    def initialize(input, opts = {})
      @io          = extract_io_from(input)
      unless @io.size == 0
        @pdf_version = read_version
        @xref        = PDF::Reader::XRef.new(@io)
        @trailer     = @xref.trailer
        @sec_handler = build_security_handler(opts)
      end
      @cache       = PDF::Reader::ObjectCache.new
    end

Then it doesn't fail anymore, but I don't know if it's the right way (I didn't took time to search/write an RSpec test now):

>> PDF::Reader.new("/srv/fundlook_testing/current/uploads/1717/empty_file.pdf")
=> #<PDF::Reader:0x10ba9608 @objects=#<PDF::Reader::ObjectHash:0x10ba9590 @io=#<StringIO:0x10ba9450>, @cache=#<PDF::Reader::ObjectCache:0x10ba9540 @objects={}>>>
@yob yob closed this issue from a commit
@yob opening an empty file should raise a MalformedPDFError
* add an integration spec to prove it
* closes #69
8fb4186
@yob yob closed this in 8fb4186
@yob
Owner

Hi, thanks for reporting this.

An empty file isn't a valid PDF, so the correct behaviour is to raise a PDF::Reader::MalformedPDFError. I've fixed this and added a spec to prevent regressions.

@zedtux

Nice and fast fix! Awesome!

Waiting for rubygems.org update! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.