Skip to content

zlib decompression produces wrong output #6606

@slonopotamus

Description

@slonopotamus

Environment Information

Provide at least:

  • JRuby version (jruby -v) and command line: jruby 9.2.16.0 (2.5.7) 2021-03-03 f82228dc32 OpenJDK 64-Bit Server VM 25.275-b01 on 1.8.0_275-b01 +jit [linux-x86_64]
  • Operating system and platform (e.g. uname -a): Linux noblesse 5.4.80-gentoo-r1 #1 SMP Tue Dec 8 10:34:59 MSK 2020 x86_64 AMD Ryzen 7 3700X 8-Core Processor AuthenticAMD GNU/Linux

Way to reproduce

  1. Download attached data.gz
  2. Run ruby -e "require 'zlib'; f = File.read('data.gz'); puts Zlib::Inflate.inflate(f).bytesize" in the directory where you saved data.gz with different Ruby implementations

Expected Behavior

Uncompressed data size is 60992 bytes. This is what MRI says and what I actually expect.

$ zlib-flate -uncompress < data.gz > data && ls -l data agrees that uncompressed data is 60992 bytes.

$ openssl zlib -d < data.gz > data && ls -l data also thinks that uncompressed data is 60992 bytes.

$ python3 -c "import zlib; print(len(zlib.decompress(open('data.gz', 'rb').read())))" also thinks that uncompressed data is 60992 bytes.

Java also agrees data is 60992 bytes:

  public static void main(String[] args) throws Exception {
    byte[] input = Files.readAllBytes(Path.of("data.gz"));
    Inflater inflater = new Inflater();
    inflater.setInput(input);

    ByteArrayOutputStream output = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];

    while (!inflater.finished()) {
      int len = inflater.inflate(buffer);
      output.write(buffer, 0, len);
    }
    System.out.println(output.toByteArray().length); // prints 60992
  }

Actual Behavior

Uncompressed data size is 60994 bytes on JRuby. I observe this on JRuby 9.2.13 and 9.2.16. I didn't test other JRuby versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions