mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
6695402: Jarsigner with multi-byte characters in class names
Reviewed-by: weijun
This commit is contained in:
parent
385c583ed1
commit
2ae9614d34
2 changed files with 219 additions and 44 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2017, 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
|
||||
|
@ -28,6 +28,7 @@ package sun.security.util;
|
|||
import java.security.*;
|
||||
import java.util.HashMap;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* This class is used to compute digests on sections of the Manifest.
|
||||
|
@ -112,8 +113,6 @@ public class ManifestDigester {
|
|||
rawBytes = bytes;
|
||||
entries = new HashMap<>();
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
Position pos = new Position();
|
||||
|
||||
if (!findSection(0, pos))
|
||||
|
@ -131,50 +130,41 @@ public class ManifestDigester {
|
|||
|
||||
if (len > 6) {
|
||||
if (isNameAttr(bytes, start)) {
|
||||
StringBuilder nameBuf = new StringBuilder(sectionLen);
|
||||
ByteArrayOutputStream nameBuf = new ByteArrayOutputStream();
|
||||
nameBuf.write(bytes, start+6, len-6);
|
||||
|
||||
try {
|
||||
nameBuf.append(
|
||||
new String(bytes, start+6, len-6, "UTF8"));
|
||||
|
||||
int i = start + len;
|
||||
if ((i-start) < sectionLen) {
|
||||
if (bytes[i] == '\r') {
|
||||
i += 2;
|
||||
} else {
|
||||
i += 1;
|
||||
}
|
||||
int i = start + len;
|
||||
if ((i-start) < sectionLen) {
|
||||
if (bytes[i] == '\r') {
|
||||
i += 2;
|
||||
} else {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
while ((i-start) < sectionLen) {
|
||||
if (bytes[i++] == ' ') {
|
||||
// name is wrapped
|
||||
int wrapStart = i;
|
||||
while (((i-start) < sectionLen)
|
||||
&& (bytes[i++] != '\n'));
|
||||
if (bytes[i-1] != '\n')
|
||||
return; // XXX: exception?
|
||||
int wrapLen;
|
||||
if (bytes[i-2] == '\r')
|
||||
wrapLen = i-wrapStart-2;
|
||||
else
|
||||
wrapLen = i-wrapStart-1;
|
||||
|
||||
nameBuf.append(new String(bytes, wrapStart,
|
||||
wrapLen, "UTF8"));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
entries.put(nameBuf.toString(),
|
||||
new Entry(start, sectionLen, sectionLenWithBlank,
|
||||
rawBytes));
|
||||
|
||||
} catch (java.io.UnsupportedEncodingException uee) {
|
||||
throw new IllegalStateException(
|
||||
"UTF8 not available on platform");
|
||||
}
|
||||
|
||||
while ((i-start) < sectionLen) {
|
||||
if (bytes[i++] == ' ') {
|
||||
// name is wrapped
|
||||
int wrapStart = i;
|
||||
while (((i-start) < sectionLen)
|
||||
&& (bytes[i++] != '\n'));
|
||||
if (bytes[i-1] != '\n')
|
||||
return; // XXX: exception?
|
||||
int wrapLen;
|
||||
if (bytes[i-2] == '\r')
|
||||
wrapLen = i-wrapStart-2;
|
||||
else
|
||||
wrapLen = i-wrapStart-1;
|
||||
|
||||
nameBuf.write(bytes, wrapStart, wrapLen);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
entries.put(new String(nameBuf.toByteArray(), UTF_8),
|
||||
new Entry(start, sectionLen, sectionLenWithBlank,
|
||||
rawBytes));
|
||||
}
|
||||
}
|
||||
start = pos.startOfNext;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue