Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Missing Zlib gzip bad stream exceptions #369

Open
drbrain opened this Issue · 1 comment

2 participants

@drbrain

When running the sparklemotion/mechanize tests I get the following errors when testing handling of bad gzip streams. Zlib::Error subclasses should be raised:

$ jruby -Ilib test/test_mechanize_http_agent.rb -n /test_response_content_encoding_gzip/
Unable to find a $JAVA_HOME at "/usr", continuing with system-provided Java...
Run options: -n /test_response_content_encoding_gzip/ --seed 64057

# Running tests:

..EFE..EE

Finished tests in 0.060000s, 150.0000 tests/s, 116.6667 assertions/s.

  1) Error:
test_response_content_encoding_gzip_checksum_truncated(TestMechanizeHttpAgent):
IOError: footer is not found
    org/jruby/ext/zlib/JZlibRubyGzipReader.java:506:in `eof'
    org/jruby/ext/zlib/JZlibRubyGzipReader.java:512:in `eof?'
    /Users/drbrain/Work/git/mechanize/lib/mechanize/http/agent.rb:1124:in `auto_io'
    /Users/drbrain/Work/git/mechanize/lib/mechanize/http/agent.rb:417:in `content_encoding_gunzip'
    /Users/drbrain/Work/git/mechanize/lib/mechanize/http/agent.rb:788:in `response_content_encoding'
    test/test_mechanize_http_agent.rb:948:in `test_response_content_encoding_gzip_checksum_truncated'
    org/jruby/RubyBasicObject.java:1667:in `__send__'

  2) Failure:
test_response_content_encoding_gzip_corrupt(TestMechanizeHttpAgent) [test/test_mechanize_http_agent.rb:890]:
[Mechanize::Error] exception expected, not
Class: <IOError>
Message: <"Unexpected end of ZLIB input stream">
---Backtrace---
org/jruby/ext/zlib/JZlibRubyGzipReader.java:506:in `eof'
org/jruby/ext/zlib/JZlibRubyGzipReader.java:512:in `eof?'
/Users/drbrain/Work/git/mechanize/lib/mechanize/http/agent.rb:1124:in `auto_io'
/Users/drbrain/Work/git/mechanize/lib/mechanize/http/agent.rb:417:in `content_encoding_gunzip'
/Users/drbrain/Work/git/mechanize/lib/mechanize/http/agent.rb:788:in `response_content_encoding'
test/test_mechanize_http_agent.rb:891:in `test_response_content_encoding_gzip_corrupt'
---------------

  3) Error:
test_response_content_encoding_gzip_no_footer(TestMechanizeHttpAgent):
IOError: footer is not found
    org/jruby/ext/zlib/JZlibRubyGzipReader.java:506:in `eof'
    org/jruby/ext/zlib/JZlibRubyGzipReader.java:512:in `eof?'
    /Users/drbrain/Work/git/mechanize/lib/mechanize/http/agent.rb:1124:in `auto_io'
    /Users/drbrain/Work/git/mechanize/lib/mechanize/http/agent.rb:417:in `content_encoding_gunzip'
    /Users/drbrain/Work/git/mechanize/lib/mechanize/http/agent.rb:788:in `response_content_encoding'
    test/test_mechanize_http_agent.rb:987:in `test_response_content_encoding_gzip_no_footer'
    org/jruby/RubyBasicObject.java:1667:in `__send__'

  4) Error:
test_response_content_encoding_gzip_checksum_corrupt_crc(TestMechanizeHttpAgent):
IOError: incorrect data check
    org/jruby/ext/zlib/JZlibRubyGzipReader.java:506:in `eof'
    org/jruby/ext/zlib/JZlibRubyGzipReader.java:512:in `eof?'
    /Users/drbrain/Work/git/mechanize/lib/mechanize/http/agent.rb:1124:in `auto_io'
    /Users/drbrain/Work/git/mechanize/lib/mechanize/http/agent.rb:417:in `content_encoding_gunzip'
    /Users/drbrain/Work/git/mechanize/lib/mechanize/http/agent.rb:788:in `response_content_encoding'
    test/test_mechanize_http_agent.rb:914:in `test_response_content_encoding_gzip_checksum_corrupt_crc'
    org/jruby/RubyBasicObject.java:1667:in `__send__'

  5) Error:
test_response_content_encoding_gzip_checksum_corrupt_length(TestMechanizeHttpAgent):
IOError: incorrect length check
    org/jruby/ext/zlib/JZlibRubyGzipReader.java:506:in `eof'
    org/jruby/ext/zlib/JZlibRubyGzipReader.java:512:in `eof?'
    /Users/drbrain/Work/git/mechanize/lib/mechanize/http/agent.rb:1124:in `auto_io'
    /Users/drbrain/Work/git/mechanize/lib/mechanize/http/agent.rb:417:in `content_encoding_gunzip'
    /Users/drbrain/Work/git/mechanize/lib/mechanize/http/agent.rb:788:in `response_content_encoding'
    test/test_mechanize_http_agent.rb:932:in `test_response_content_encoding_gzip_checksum_corrupt_length'
    org/jruby/RubyBasicObject.java:1667:in `__send__'

9 tests, 7 assertions, 1 failures, 4 errors, 0 skips
@headius
Owner

So I looked at this with @drbrain a bit. The problem here is that jzlib is basically just raising IOException for all these error conditions that could be independent exception types. The result is that we can't distinguish them other than by their messages, which is about as brittle as it can be.

A short term ugly fix would be to check the error messages and raise the right Ruby exception based on that. The right fix is to patch jzlib to raise more identifiable errors for these cases, so we can re-raise correctly.

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.