Skip to content

Commit

Permalink
prohibits too many items from being added to a constant pool.
Browse files Browse the repository at this point in the history
the previous commit was wrong.
  • Loading branch information
chibash committed Aug 6, 2022
1 parent 4f35e4e commit 3528a20
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Binary file modified javassist.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/javassist/bytecode/ConstPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ private int readOne(DataInputStream in) throws IOException
*/
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);
Expand Down
9 changes: 7 additions & 2 deletions src/test/javassist/JvstTest5.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,13 @@ 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);
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");
Expand Down

0 comments on commit 3528a20

Please sign in to comment.