JDK-6372077 : JarFile.getManifest() should handle manifest attribute name 70 bytes
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 1.0,5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-01-12
  • Updated: 2019-01-18
  • Resolved: 2018-03-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11
11 b04Fixed
Related Reports
Relates :  
Relates :  
Description
The following code, JarFile.getManifest(), throw IOException: invalid header field 
when the manifest contains header name with 70 bytes. 

JAR Manifest specification state:"
 Because header names cannot be continued, the maximum length of a header name is 70 bytes (there must be a colon and a SPACE after the name)."
getManifest() should not throw IOException at 70 bytes header name (current, it handle up to 69 bytes.)

import java.io.*;
import java.util.*;
import java.util.jar.*;
    
public class ManifestTest {
  public static void main(String args[])
  {
    if (args.length != 1) {
      System.err.println("usage: manif file.jar");
      System.exit(1);
    }
    
    try {
      JarFile jf = new JarFile(args[0]);
      Manifest manif = jf.getManifest();
      /*
      if (manif != null) {
        manif.write(System.out);
        Attributes attr =
          manif.getMainAttributes();
        String attrname =
          "Specification-Version";
        String str =
          attr.getValue(attrname);
        System.out.println(str);
      }
      */
    }
    catch (IOException e) {
      System.err.println(e);
    }
  }
}

Comments
EVALUATION The problem is not completely with reading of manifest entries, it is also with writing them: Our code can write invalid entries. Attributes.isValid() allows an entry's name to be 70 characters long. However, when Attributes.writeMain is invoked while creating the jar, the last character on the line is \r, not a space. Subsequently, when reading the file, Attributes.read() throws an IOException from the second of the two sites that throw an IOException with "invalid header field".
13-01-2006