Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8292327

java.io.EOFException in InflaterInputStream after JDK-8281962

    XMLWordPrintable

Details

    • 19
    • b11
    • Not verified

    Description

      The following program crashes with a java.io.EOFException after the fix for JDK-8281962 (Avoid unnecessary native calls in InflaterInputStream). Is this an expected result of that change, or a potential regression?

      The repro creates an InflaterInputStream for the included byte array. Reading the entire stream using readAllBytes works, and I think the input is well-formed.

      Reading the first 128 bytes, and then doing a second read, causes a crash.

      $ java B
      Exception in thread "main" java.io.EOFException: Unexpected end of ZLIB input stream
              at java.base/java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:245)
              at java.base/java.util.zip.InflaterInputStream.read(InflaterInputStream.java:159)
              at B.main(B.java:29)

      ===
      import java.io.ByteArrayInputStream;
      import java.io.IOException;
      import java.util.zip.Inflater;
      import java.util.zip.InflaterInputStream;

      import static java.nio.charset.StandardCharsets.UTF_8;

      public class B {
        public static void main(String[] args) throws IOException {
          byte[] bytes = {
            85, -115, 49, 14, -125, 48, 12, 0, -9, -68, 2, 49, -63, 98, -87, 93, 89, 90, -47, -103, 14,
            -99, 58, -102, 96, 5, -89, 36, -74, -120, -123, -44, -33, -61, 8, -21, -23, 78, -9, 120, -113,
            -111, -68, -15, 70, -3, -128, -119, -102, -6, -11, 29, 62, 79, -27, -70, 117, -118, -2, -121,
            -127, 42, 47, 9, -126, 72, 88, 8, 80, -75, -64, -12, -49, -104, -40, 8, -74, 27, -108, 25, 87,
            -102, 14, -50, -99, 115, -100, 84, 86, 59, -5, -15, 46, 99, -12, -128, 57, -117, -95, -79,
            -28, 2, -41, -33, 81, -19,
          };

          // using readAllBytes succeeds, the underlying gzip data seems to be well-formed
          byte[] inflated =
              new InflaterInputStream(new ByteArrayInputStream(bytes), new Inflater(/*nowrap=*/ true))
              .readAllBytes();

          // a 128 byte read followed by a 512 byte read fails after JDK-8281962
          InflaterInputStream is =
              new InflaterInputStream(new ByteArrayInputStream(bytes), new Inflater(/*nowrap=*/ true));
          byte[] buf = new byte[512];
          is.read(buf, 0, 128);
          is.read(buf, 0, 512); // Unexpected end of ZLIB input stream
        }
      }
      ===

      Attachments

        Issue Links

          Activity

            People

              simonis Volker Simonis
              cushon Liam Miller-Cushon
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: