opened
bcoles
username_0
pdf-reader crashes with the attached malformed PDF file.

[20170708204242079587195_test_652.pdf](https://github.com/username_2/pdf-reader/files/1133488/20170708204242079587195_test_652.pdf)


### Crash

```
[*] Processing 'crashes/20170708204242079587195_test_652.pdf'
/usr/local/rvm/gems/ruby-2.3.0/gems/ruby-rc4-0.1.5/lib/rc4.rb:5:in `initialize': RC4: Key supplied is blank (SyntaxError)
	from /usr/local/rvm/gems/ruby-2.3.0/gems/pdf-reader-2.0.0/lib/pdf/reader/standard_security_handler.rb:158:in `new'
	from /usr/local/rvm/gems/ruby-2.3.0/gems/pdf-reader-2.0.0/lib/pdf/reader/standard_security_handler.rb:158:in `block in auth_owner_pass'
	from /usr/local/rvm/gems/ruby-2.3.0/gems/pdf-reader-2.0.0/lib/pdf/reader/standard_security_handler.rb:158:in `downto'
	from /usr/local/rvm/gems/ruby-2.3.0/gems/pdf-reader-2.0.0/lib/pdf/reader/standard_security_handler.rb:158:in `each'
	from /usr/local/rvm/gems/ruby-2.3.0/gems/pdf-reader-2.0.0/lib/pdf/reader/standard_security_handler.rb:158:in `auth_owner_pass'
	from /usr/local/rvm/gems/ruby-2.3.0/gems/pdf-reader-2.0.0/lib/pdf/reader/standard_security_handler.rb:220:in `build_standard_key'
	from /usr/local/rvm/gems/ruby-2.3.0/gems/pdf-reader-2.0.0/lib/pdf/reader/standard_security_handler.rb:57:in `initialize'
	from /usr/local/rvm/gems/ruby-2.3.0/gems/pdf-reader-2.0.0/lib/pdf/reader/object_hash.rb:295:in `new'
	from /usr/local/rvm/gems/ruby-2.3.0/gems/pdf-reader-2.0.0/lib/pdf/reader/object_hash.rb:295:in `build_security_handler'
	from /usr/local/rvm/gems/ruby-2.3.0/gems/pdf-reader-2.0.0/lib/pdf/reader/object_hash.rb:49:in `initialize'
	from /usr/local/rvm/gems/ruby-2.3.0/gems/pdf-reader-2.0.0/lib/pdf/reader.rb:116:in `new'
	from /usr/local/rvm/gems/ruby-2.3.0/gems/pdf-reader-2.0.0/lib/pdf/reader.rb:116:in `initialize'
	from ./read-pdf.rb:43:in `new'
	from ./read-pdf.rb:43:in `read'
	from ./read-pdf.rb:95:in `<main>'
```


### Reproduce

```
#!/usr/bin/env ruby
require 'pdf-reader'
require 'colorize'

$QUIET = false

#
# Print status message
#
# @param [String] msg message to print
#
def print_status(msg = '')
  puts '[*] '.blue + msg unless $QUIET
end

#
# Print progress messages
#
# @param [String] msg message to print
#
def print_good(msg = '')
  puts '[+] '.green + msg unless $QUIET
end

#
# Print error message
#
# @param [String] msg message to print
#
def print_error(msg = '')
  puts '[-] '.red + msg unless $QUIET
end

#
# Read a PDF file
#
# @param [File] file PDF file
#
def read doc
  print_status "Processing '#{doc}'"
  begin
    @fname = doc
    reader = PDF::Reader.new(@fname)
  rescue PDF::Reader::MalformedPDFError
    print_error "Could not parse PDF '#{doc}': PDF is malformed"
    exit 1
  rescue PDF::Reader::UnsupportedFeatureError 
    print_error "Could not parse PDF '#{doc}': PDF::Reader::UnsupportedFeatureError"
    exit 1
  end
  print_good 'Processing complete'

  print_status "Parsing '#{@fname}'"
  begin
    parse reader
  rescue PDF::Reader::UnsupportedFeatureError
    print_error "Could not parse PDF '#{doc}': PDF::Reader::UnsupportedFeatureError"
    exit 1
  rescue PDF::Reader::MalformedPDFError => e
    print_error "Could not parse PDF '#{doc}': PDF is malformed"
    exit 1
  end
  print_good 'Parsing complete'
end

#
# parse pdf
#
def parse(reader)
  print_status "Version: #{reader.pdf_version}"
  print_status "Info: #{reader.info}"
  print_status "Metadata: #{reader.metadata}"
  print_status "Objects: #{reader.objects}"
  print_status "Pages: #{reader.page_count}"

  print_status 'Dumping PDF contents...'
  contents = ''
  reader.pages.each do |page|
    contents << page.text.to_s
    contents << page.fonts.to_s
    contents << page.text.to_s
    contents << page.raw_content.to_s
  end
  #puts contents unless $QUIET
end

def usage
  print_status "./read-pdf.rb <FILE>"
  exit 1
end

doc = ARGV[0]
usage if doc.nil?

if File.exist? doc
  read doc
  exit 0
else
  print_error "Could not find #{doc}"
  exit 1
end
```
Malformed PDF raises `RC4: Key supplied is blank (SyntaxError)`
issue
created
bcoles
username_0
This issue is problematic as `SyntaxError` will not be handled by a `rescue` clause unless the author is in the bad habit of using `rescue Exception`, or happens to `rescue SyntaxError` specifically.
comment
created
ndbroadbent
username_1
Can this also be closed? (See: #249 and https://github.com/caiges/Ruby-RC4/pull/15)

Or should pdf-reader also raise a `MalformedPDFError` in this case?
comment
created
bcoles
username_0
@username_1 This issue is not resolved.

The Ruby-RC4 library has been patched and no longer raises `SyntaxError`, but a new version of the gem hasn't been released (since 2012).

This issue cannot be closed until a new version of Ruby-RC4 is released, or if the Gemfile is modified to pull the dependency in directly from Github, which isn't ideal.

I created PR #249 to raise `ArgumentError` rather than `SyntaxError`, but closed the PR on the assumption that the Ruby RC4 team would release a new version in a timely manner. That turns out to have been an unsafe assumption.
comment
closed
yob
username_2
issue