diff options
author | chibash <chiba@javassist.org> | 2022-08-07 04:06:50 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2022-08-07 04:06:50 +0900 |
commit | 3528a20dd925388c01330b950d0f3ad75f7a14e5 (patch) | |
tree | a91523fb9843d8c9a6e86364ab005f55f6b295fa /src | |
parent | 4f35e4e1a8c76fa7da07a92674ffddd5c4c27ec0 (diff) | |
download | javassist-3528a20dd925388c01330b950d0f3ad75f7a14e5.tar.gz javassist-3528a20dd925388c01330b950d0f3ad75f7a14e5.zip |
prohibits too many items from being added to a constant pool.
the previous commit was wrong.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/javassist/bytecode/ConstPool.java | 2 | ||||
-rw-r--r-- | src/test/javassist/JvstTest5.java | 9 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/main/javassist/bytecode/ConstPool.java b/src/main/javassist/bytecode/ConstPool.java index b5113e42..e8434dce 100644 --- a/src/main/javassist/bytecode/ConstPool.java +++ b/src/main/javassist/bytecode/ConstPool.java @@ -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); diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java index 39af16b9..4a370632 100644 --- a/src/test/javassist/JvstTest5.java +++ b/src/test/javassist/JvstTest5.java @@ -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"); |