6372077: JarFile.getManifest() should handle manifest attribute name 70 bytes

Reviewed-by: alanb, sherman
This commit is contained in:
Philipp Kunz 2018-03-01 15:50:26 -05:00 committed by Roger Riggs
parent 3a03cd060f
commit 5db337db24
4 changed files with 298 additions and 14 deletions

View file

@ -40,7 +40,9 @@ import sun.util.logging.PlatformLogger;
* The Attributes class maps Manifest attribute names to associated string
* values. Valid attribute names are case-insensitive, are restricted to
* the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed 70
* characters in length. Attribute values can contain any characters and
* characters in length. There must be a colon and a SPACE after the name;
* the combined length will not exceed 72 characters.
* Attribute values can contain any characters and
* will be UTF8-encoded when written to the output stream. See the
* <a href="{@docRoot}/../specs/jar/jar.html">JAR File Specification</a>
* for more information about valid attribute names and values.
@ -310,8 +312,8 @@ public class Attributes implements Map<Object,Object>, Cloneable {
}
buffer.append(value);
buffer.append("\r\n");
Manifest.make72Safe(buffer);
buffer.append("\r\n");
os.writeBytes(buffer.toString());
}
os.writeBytes("\r\n");
@ -355,8 +357,8 @@ public class Attributes implements Map<Object,Object>, Cloneable {
}
buffer.append(value);
buffer.append("\r\n");
Manifest.make72Safe(buffer);
buffer.append("\r\n");
out.writeBytes(buffer.toString());
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -157,8 +157,8 @@ public class Manifest implements Cloneable {
value = new String(vb, 0, 0, vb.length);
}
buffer.append(value);
buffer.append("\r\n");
make72Safe(buffer);
buffer.append("\r\n");
dos.writeBytes(buffer.toString());
e.getValue().write(dos);
}
@ -170,13 +170,11 @@ public class Manifest implements Cloneable {
*/
static void make72Safe(StringBuffer line) {
int length = line.length();
if (length > 72) {
int index = 70;
while (index < length - 2) {
line.insert(index, "\r\n ");
index += 72;
length += 3;
}
int index = 72;
while (index < length) {
line.insert(index, "\r\n ");
index += 74; // + line width + line break ("\r\n")
length += 3; // + line break ("\r\n") and space
}
return;
}