Skip to content

Commit

Permalink
Detect jump's that are bigger than allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Jul 18, 2012
1 parent ea4d6e2 commit eda6e4f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/org/jboss/classfilewriter/code/CodeAttribute.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -301,10 +301,14 @@ public void bipush(byte value) {
*/ */
public void branchEnd(BranchEnd end) { public void branchEnd(BranchEnd end) {
mergeStackFrames(end.getStackFrame()); mergeStackFrames(end.getStackFrame());
final int jump = currentOffset - end.getOffsetLocation();
if (end.isJump32Bit()) { if (end.isJump32Bit()) {
jumpLocations32.put(end.getBranchLocation(), currentOffset - end.getOffsetLocation()); jumpLocations32.put(end.getBranchLocation(), jump);
} else { } 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);
} }
} }


Expand Down Expand Up @@ -2091,6 +2095,9 @@ private void writeByte(int n) {


private void writeShort(int n) { private void writeShort(int n) {
try { try {
if(n > Short.MAX_VALUE) {
throw new RuntimeException(n + " is to big to be written as a 16 bit value");
}
data.writeShort(n); data.writeShort(n);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
Expand Down

0 comments on commit eda6e4f

Please sign in to comment.