diff options
author | Shigeru Chiba <chibash@users.noreply.github.com> | 2021-04-26 02:13:44 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-26 02:13:44 +0900 |
commit | 84c176a6e03fe56debdef02f7864d624c79f4d55 (patch) | |
tree | ef746e3bc9ba307b54d9717570a91e71acf9c63d /src/test | |
parent | 0d468da4e95daeef7413c99a81b71d72eb8e7cad (diff) | |
parent | d2e757ee44c6425bd801b6f76ff14537203281b9 (diff) | |
download | javassist-84c176a6e03fe56debdef02f7864d624c79f4d55.tar.gz javassist-84c176a6e03fe56debdef02f7864d624c79f4d55.zip |
Merge pull request #351 from sgjesse/issue-350
This fixes Issue #350.
Check for extended frame type when updating StackMapTable offset.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/javassist/bytecode/StackMapTest.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/test/javassist/bytecode/StackMapTest.java b/src/test/javassist/bytecode/StackMapTest.java index 7ea415a9..a0a4f1b1 100644 --- a/src/test/javassist/bytecode/StackMapTest.java +++ b/src/test/javassist/bytecode/StackMapTest.java @@ -923,4 +923,81 @@ public class StackMapTest extends TestCase { else ci.insert(newCode.get()); } + + public void testIssue350() throws Exception { + byte sameLocals1StackItemFrameExtended = 247 - 256; + byte sameFrameExtended = 251 - 256; + byte appendFrame = 252 - 256; + ConstPool cp = new ConstPool("Test"); + StackMapTable stmt; + int originalLength; + + stmt = new StackMapTable(cp, new byte[] { + 0, 1, + sameLocals1StackItemFrameExtended, 0, 63, 1 + }); + originalLength = stmt.info.length; + assertEquals(63, stmt.info[4]); + stmt.shiftPc(0, 2, false); + assertEquals(originalLength, stmt.info.length); + assertEquals(65, stmt.info[4]); + + stmt = new StackMapTable(cp, new byte[] { + 0, 1, + sameFrameExtended, 0, 63 + }); + originalLength = stmt.info.length; + assertEquals(63, stmt.info[4]); + stmt.shiftPc(0, 2, false); + assertEquals(originalLength, stmt.info.length); + assertEquals(65, stmt.info[4]); + + stmt = new StackMapTable(cp, new byte[] { + 0, 2, + sameLocals1StackItemFrameExtended, 0, 63, 1, + sameFrameExtended, 0, 63 + }); + originalLength = stmt.info.length; + assertEquals(63, stmt.info[4]); + assertEquals(63, stmt.info[8]); + stmt.shiftPc(0, 2, false); + assertEquals(originalLength, stmt.info.length); + assertEquals(65, stmt.info[4]); + assertEquals(63, stmt.info[8]); + stmt.shiftPc(100, 2, false); + assertEquals(65, stmt.info[4]); + assertEquals(65, stmt.info[8]); + + // Actual StackMapTable reported in https://github.com/jboss-javassist/javassist/issues/350. + stmt = new StackMapTable(cp, new byte[] { + 0, 7, // size + sameLocals1StackItemFrameExtended, 0, 76, 7, 2, 206 - 256, + sameLocals1StackItemFrameExtended, 0, 63, 7, 2, 221 - 256, + appendFrame, 0, 63, 7, 0, 14, + appendFrame, 0, 43, 7, 2, 225 - 256, 1, + 74, 7, 0, 19, // same_locals_1_stack_item_frame (not extended) + appendFrame, 0, 23, 7, 0, 19, + 66, 7, 2, 225 - 256 // same_locals_1_stack_item_frame (not extended) + }); + assertEquals(63, stmt.info[10]); + originalLength = stmt.info.length; + + stmt.shiftPc(100, 2, false); + assertEquals(originalLength, stmt.info.length); + assertEquals(65, stmt.info[10]); + } + + public static void dump(byte[] content) { + final int bytesPerLine = 16; + for (int i = 0; i < content.length; i += bytesPerLine) { + for (int j = 0; j < bytesPerLine && i + j < content.length; j++) { + int unsignedByte = content[i + j]; + if (unsignedByte < 0) { + unsignedByte = 256 + unsignedByte; + } + System.out.print(unsignedByte + ", "); + } + System.out.println(); + } + } } |