Browse files

Detect jump's that are bigger than allowed

  • Loading branch information...
1 parent ea4d6e2 commit eda6e4f6b772155dc5b133a0c97bf1b9f7bef2a3 @stuartwdouglas stuartwdouglas committed Jul 18, 2012
Showing with 9 additions and 2 deletions.
  1. +9 −2 src/main/java/org/jboss/classfilewriter/code/CodeAttribute.java
View
11 src/main/java/org/jboss/classfilewriter/code/CodeAttribute.java
@@ -301,10 +301,14 @@ public void bipush(byte value) {
*/
public void branchEnd(BranchEnd end) {
mergeStackFrames(end.getStackFrame());
+ final int jump = currentOffset - end.getOffsetLocation();
if (end.isJump32Bit()) {
- jumpLocations32.put(end.getBranchLocation(), currentOffset - end.getOffsetLocation());
+ jumpLocations32.put(end.getBranchLocation(), jump);
} else {
- jumpLocations.put(end.getBranchLocation(), currentOffset - end.getOffsetLocation());
+ if(jump > Short.MAX_VALUE) {
+ throw new RuntimeException(jump + " is to big to be written as a 16 bit value");
+ }
+ jumpLocations.put(end.getBranchLocation(), jump);
}
}
@@ -2091,6 +2095,9 @@ private void writeByte(int n) {
private void writeShort(int n) {
try {
+ if(n > Short.MAX_VALUE) {
+ throw new RuntimeException(n + " is to big to be written as a 16 bit value");
+ }
data.writeShort(n);
} catch (IOException e) {
throw new RuntimeException(e);

0 comments on commit eda6e4f

Please sign in to comment.