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

Classes in java.util.zip have incorrect statement about maximum string length in some methods

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      Some java.util.zip APIs specify the maximum length of string as a parameter. For example, java.util.zip.ZipEntry.ZipEntry(String name)
      states:

      IllegalArgumentException - if the entry name is longer than 0xFFFF bytes

      However, this statement is not true if the string is created
      with 0xFFFF + 1 bytes under UTF-16 encoding. See the following program:

      import java.util.zip.*;
      import java.io.*;

      public class ZipEntryTest {
          public static void main(String[] args) throws Exception {
              try {
                  ZipEntry entry = new ZipEntry(new String(new byte[0xffff + 1], "UTF-8"));
              } catch (IllegalArgumentException e) {
                  System.out.println("IllegalArgumentException is thrown as expected for UTF-8 encoding");
              }
              try {
                  ZipEntry entry = new ZipEntry(new String(new byte[0xffff + 1], "UTF-16"));
                  System.out.println("No exception is thrown for ZipEntry created with UTF-16 encoding");
              } catch (IllegalArgumentException e) {
                  e.printStackTrace();
              }
                          
          }
      }

      The output is:

      IllegalArgumentException is thrown as expected for UTF-8 encoding
      No exception is thrown for ZipEntry created with UTF-16 encoding

      So it seems that the maximum length of string should be defined
      as number of characters, instead of number of bytes.

      The following methods are affected by this bug:

      ZipEntry.ZipEntry(String name)
      ZipEntry.setComment(String comment)
      ZipOutputStream.setComment(String comment)

      ###@###.### 2005-03-23 22:08:45 GMT
      ###@###.### 2005-03-23 22:39:14 GMT

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sherman Xueming Shen
                Reporter:
                xwangsunw Xiaozhong Wang (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: