]> source.dussan.org Git - javassist.git/commitdiff
prohibits too many items from being added to a constant pool.
authorchibash <chiba@javassist.org>
Sat, 6 Aug 2022 19:06:50 +0000 (04:06 +0900)
committerchibash <chiba@javassist.org>
Sat, 6 Aug 2022 19:06:50 +0000 (04:06 +0900)
the previous commit was wrong.

javassist.jar
src/main/javassist/bytecode/ConstPool.java
src/test/javassist/JvstTest5.java

index fcead50d48f9486ec9dab284816ed81d0d26c9a4..7d607ff106ae2bcd313ec32d28feef253f730728 100644 (file)
Binary files a/javassist.jar and b/javassist.jar differ
index b5113e42848f3bd7814f9581d966bb3ce3fa5e98..e8434dce2d5fb0feb1f7365f87a6042bde88b37c 100644 (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);
index 39af16b9f502f2e89296a6f1cd20c123b673b8c9..4a370632664521adca4fa864bb4448704ae65291 100644 (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");