Browse Source

prohibits too many items from being added to a constant pool.

the previous commit was wrong.
tags/rel_3_29_1_ga
chibash 1 year ago
parent
commit
3528a20dd9
3 changed files with 8 additions and 3 deletions
  1. BIN
      javassist.jar
  2. 1
    1
      src/main/javassist/bytecode/ConstPool.java
  3. 7
    2
      src/test/javassist/JvstTest5.java

BIN
javassist.jar View File


+ 1
- 1
src/main/javassist/bytecode/ConstPool.java View File

@@ -1433,7 +1433,7 @@ public final class ConstPool
*/
public void write(DataOutputStream out) throws IOException
{
if (numOfItems < 0 || Short.MAX_VALUE < numOfItems)
if (numOfItems < 0 || ((1 << 16) - 1) < numOfItems)
throw new IOException("too many constant pool items " + numOfItems);

out.writeShort(numOfItems);

+ 7
- 2
src/test/javassist/JvstTest5.java View File

@@ -580,8 +580,13 @@ public class JvstTest5 extends JvstTestRoot {
CtClass cc = sloader.makeClass("TooManyConstPoolItems");
ClassFile cf = cc.getClassFile();
ConstPool cPool = cf.getConstPool();
for (int i = 0; i <= 65527; i++)
cPool.addIntegerInfo(i);
int size = cPool.getSize();
while (cPool.getSize() < 65536 - 6)
cPool.addIntegerInfo(cPool.getSize());

cc.writeFile();
cc.defrost();
cPool.addIntegerInfo(-1);
try {
cc.writeFile();
fail("too many items were accepted");

Loading…
Cancel
Save