# HG changeset patch # User twisti # Date 1389326695 28800 # Node ID 7737fbb055b0923288a47e8bfe0cc4f9c908fd2e # Parent f4f0a8a01ce0b4e8bcb4fa2c3fa7618af0a9fcc7 check branch displacement when patching short branches diff -r f4f0a8a01ce0 -r 7737fbb055b0 graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Assembler.java --- a/graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Assembler.java Thu Jan 09 16:18:29 2014 +0100 +++ b/graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Assembler.java Thu Jan 09 20:04:55 2014 -0800 @@ -2437,7 +2437,14 @@ } else if (op == 0xEB || (op & 0xF0) == 0x70) { // short offset operators (jmp and jcc) - int imm8 = branchTarget - (branch + 2); + final int imm8 = branchTarget - (branch + 2); + /* + * Since a wrongly patched short branch can potentially lead to working but really bad + * behaving code we should always fail with an exception instead of having an assert. + */ + if (!NumUtil.isByte(imm8)) { + throw new InternalError("branch displacement out of range: " + imm8); + } codeBuffer.emitByte(imm8, branch + 1); } else {