]> 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 18:01:40 +0000 (03:01 +0900)
committerchibash <chiba@javassist.org>
Sat, 6 Aug 2022 18:01:40 +0000 (03:01 +0900)
javassist.jar
src/main/javassist/bytecode/ConstPool.java
src/test/javassist/JvstTest5.java

index bcdd5600318c781d566a49ecb6b1cb42da4aa7d4..fcead50d48f9486ec9dab284816ed81d0d26c9a4 100644 (file)
Binary files a/javassist.jar and b/javassist.jar differ
index 1ce26b3ec90d7964ea172cc27f8a184cf2334457..b5113e42848f3bd7814f9581d966bb3ce3fa5e98 100644 (file)
@@ -1433,6 +1433,9 @@ public final class ConstPool
      */
     public void write(DataOutputStream out) throws IOException
     {
+        if (numOfItems < 0 || Short.MAX_VALUE < numOfItems)
+            throw new IOException("too many constant pool items " + numOfItems);
+
         out.writeShort(numOfItems);
         LongVector v = items;
         int size = numOfItems;
index ade41e8cf6323c4e93edf43074eb234bbd21c4d0..39af16b9f502f2e89296a6f1cd20c123b673b8c9 100644 (file)
@@ -15,6 +15,7 @@ import javassist.expr.ExprEditor;
 import javassist.expr.Handler;
 import javassist.expr.MethodCall;
 import javassist.expr.NewExpr;
+import junit.framework.Assert;
 
 @SuppressWarnings({"rawtypes","unchecked","unused"})
 public class JvstTest5 extends JvstTestRoot {
@@ -574,4 +575,17 @@ public class JvstTest5 extends JvstTestRoot {
         Object obj = make(cc.getName());
         assertEquals(1, invoke(obj, "run"));
     }
+
+    public void testTooManyConstPoolItems() throws Exception {
+        CtClass cc = sloader.makeClass("TooManyConstPoolItems");
+        ClassFile cf = cc.getClassFile();
+        ConstPool cPool = cf.getConstPool();
+        for (int i = 0; i <= 65527; i++)
+            cPool.addIntegerInfo(i);
+        try {
+            cc.writeFile();
+            fail("too many items were accepted");
+        }
+        catch (CannotCompileException e) {}
+    }
 }