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

GZIP "OS" header flag hard-coded to 0 instead of 255 (RFC 1952 non-compliance)

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Running Windows 10 Pro 64-bit with Java 11.0.7.

      A DESCRIPTION OF THE PROBLEM :
      Line 193 of java.util.zip.GZIPOutputStream hard-codes the value of the OS flag in all written GZIP headers to 0. This appears to go against section 2.3.1.2 of RFC 1952 ("GZIP file format"), which specifies that a value of 255 for the OS flag should be provided as a default.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Deflate any String (such as "Hello World") using a GZIPOutputStream. Inspect the resulting byte array at index 9. This is the tenth and last bit of the GZIP header, which precedes the compressed blocks,


      ---------- BEGIN SOURCE ----------
      import java.io.ByteArrayOutputStream;
      import java.io.IOException;
      import java.util.zip.GZIPOutputStream;

      public class Main {

          public static void main(String[] args) throws IOException {
              byte[] compressed = compress("Hello World");
              System.out.println("Tenth bit (OS flag) = " + compressed[9]);
          }

          private static byte[] compress(String s) throws IOException {
              ByteArrayOutputStream bytes = new ByteArrayOutputStream();

              try (GZIPOutputStream gzip = new GZIPOutputStream(bytes)) {
                  gzip.write(s.getBytes());
              }

              return bytes.toByteArray();
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Manually set the tenth byte in the compressed byte array to 255.

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              lancea Lance Andersen
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: