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

Improve handling of zip encoding through use of property flag

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P3
    • Resolution: Won't Fix
    • Affects Version/s: 1.4.2
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:
      None

      Backports

        Description

        Dear all,

        This RFE / defect is concerning a functionality reported by SAP in their internal issue tracking system. The issue is attached to this report for your analysis and I'm just expecting whether this is a functionality that could be built into the JDK 1.4.2 considering the EOL in Septermber. I'm simply expecting a Go or No-Go evaluation that I could report to SAP.

        Thank you very much.

        Here is the snippet from SAP :


        There are problems with ZIP handling of files with non-UTF8 encoded
        file names.
        See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4244499.

        In order to improve the situation without changing existing APIs
        SAP has implemented following solution for java.util.zip.ZipInputStream
        into SAPJVM 5.1 and suggests that SUN should think about a similar
        approach for JDK 1.4.2, because we were faced with customer problems on
        this version:

        A new System Property called com.sap.jvm.ZipEntry.encoding was added
        with the following behavior:

         not set: Reading ZIP files with entries with non-UTF8 chars will fail
                  with IllegalArgumentException as before this change, but with

                  a useful message pointing to the cause of the problem and
                  the new System Property
         "default": If decoding an entry name with UTF8 fails, try the
                    platform's default encoding. Reading ZIP files will succeed,
                    but filenames might be wrong
         <encoding>: If decoding an entry name with UTF8 fails, try the given
                     encoding. If the right encoding is given, reading the ZIP
                     file will succeed and entry names will be converted
                     correctly. WinRar and WinZip seem to use "Cp437" encoding.

        The piece of code looks like this:

         Replace

           ZipEntry e = createZipEntry(getUTF8String(b, 0, len));

         by

           // SAPJVM SS 2008-07-02 implemented workaround to be able to use
           // non-UTF8 encoded zip entry names
           String filename = null;
           try {
               // First try getUTF8String for compatibility
               filename = getUTF8String(b, 0, len);
           }
           catch (IllegalArgumentException e) {
               // UTF8 decoding failed!
               // alternative encoding requested?
               String encoding = System.getProperty("com.sap.jvm.ZipEntry.
        encoding");
               if (encoding == null) {
                   // no alternative encoding requested, just throw the
                   // Exception (for compatibility), but add a message
                   IllegalArgumentException ee = new IllegalArgumentException(
                           "zip entry name contained non-utf8 chars, try system
        property " +
                           "com.sap.jvm.ZipEntry.encoding");
                   ee.setStackTrace(e.getStackTrace());
                   throw ee;
               }
               // an alternative encoding is requested
               if (encoding.equalsIgnoreCase("default")) {
                   // use platform's default encoding

                   filename = new String(b, 0, len);
               }
               else {
                   // use the specified encoding
                   // (WinZip and WinRar seem to use Cp437 )
                   filename = new String(b, 0, len, encoding);
               }
           }
           ZipEntry e = createZipEntry(filename);

        Please check whether you could enter such a solution into JDK 1.4.2.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  sherman Xueming Shen
                  Reporter:
                  duke J. Duke (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: