Skip to content

Commit 5d1c448

Browse files
JoeWang-Javaslowhog
authored andcommittedJul 19, 2022
8285407: Improve Xalan supports
Reviewed-by: naoto, lancea, ahgross, rhalade
1 parent d0a2f13 commit 5d1c448

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed
 

‎src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/ConstantPool.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
2-
* reserved comment block
3-
* DO NOT REMOVE OR ALTER!
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
43
*/
54
/*
65
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -26,6 +25,7 @@
2625
import java.io.IOException;
2726

2827
import com.sun.org.apache.bcel.internal.Const;
28+
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
2929

3030
/**
3131
* This class represents the constant pool, i.e., a table of constants, of
@@ -37,6 +37,7 @@
3737
3838
* @see Constant
3939
* @see com.sun.org.apache.bcel.internal.generic.ConstantPoolGen
40+
* @LastModified: May 2022
4041
*/
4142
public class ConstantPool implements Cloneable, Node {
4243

@@ -222,8 +223,16 @@ public String constantToString( final int index, final byte tag ) throws ClassFo
222223
* @throws IOException
223224
*/
224225
public void dump( final DataOutputStream file ) throws IOException {
225-
file.writeShort(constantPool.length);
226-
for (int i = 1; i < constantPool.length; i++) {
226+
/*
227+
* Constants over the size of the constant pool shall not be written out.
228+
* This is a redundant measure as the ConstantPoolGen should have already
229+
* reported an error back in the situation.
230+
*/
231+
int size = constantPool.length < ConstantPoolGen.CONSTANT_POOL_SIZE - 1 ?
232+
constantPool.length : ConstantPoolGen.CONSTANT_POOL_SIZE - 1;
233+
234+
file.writeShort(size);
235+
for (int i = 1; i < size; i++) {
227236
if (constantPool[i] != null) {
228237
constantPool[i].dump(file);
229238
}

‎src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ConstantPoolGen.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -50,10 +50,10 @@
5050
* JVM and that Double and Long constants need two slots.
5151
*
5252
* @see Constant
53-
* @LastModified: May 2021
53+
* @LastModified: May 2022
5454
*/
5555
public class ConstantPoolGen {
56-
56+
public static final int CONSTANT_POOL_SIZE = 65536;
5757
private static final int DEFAULT_BUFFER_SIZE = 256;
5858
private int size;
5959
private Constant[] constants;
@@ -83,7 +83,7 @@ private static class Index {
8383
public ConstantPoolGen(final Constant[] cs) {
8484
final StringBuilder sb = new StringBuilder(DEFAULT_BUFFER_SIZE);
8585

86-
size = Math.max(DEFAULT_BUFFER_SIZE, cs.length + 64);
86+
size = Math.min(Math.max(DEFAULT_BUFFER_SIZE, cs.length + 64), CONSTANT_POOL_SIZE);
8787
constants = new Constant[size];
8888

8989
System.arraycopy(cs, 0, constants, 0, cs.length);
@@ -212,9 +212,18 @@ public ConstantPoolGen() {
212212
/** Resize internal array of constants.
213213
*/
214214
protected void adjustSize() {
215+
// 3 extra spaces are needed as some entries may take 3 slots
216+
if (index + 3 >= CONSTANT_POOL_SIZE) {
217+
throw new RuntimeException("The number of constants " + (index + 3)
218+
+ " is over the size of the constant pool: "
219+
+ (CONSTANT_POOL_SIZE - 1));
220+
}
221+
215222
if (index + 3 >= size) {
216223
final Constant[] cs = constants;
217224
size *= 2;
225+
// the constant array shall not exceed the size of the constant pool
226+
size = Math.min(size, CONSTANT_POOL_SIZE);
218227
constants = new Constant[size];
219228
System.arraycopy(cs, 0, constants, 0, index);
220229
}

0 commit comments

Comments
 (0)