Skip to content

Commit 7a205f0

Browse files
author
thk123
committed
Correct handling of two byte offsets
TODO: test the 4 last offset fixes
1 parent 0df054c commit 7a205f0

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/java_bytecode/java_bytecode_parser.cpp

+15-5
Original file line numberDiff line numberDiff line change
@@ -756,17 +756,21 @@ void java_bytecode_parsert::rbytecode(
756756
case 'o': // two byte branch offset, signed
757757
{
758758
s2 offset=read_u2();
759+
// By converting the signed offset into an absolute address (by adding
760+
// the current address) the number represented becomes unsigned.
759761
instruction.args.push_back(
760-
from_integer(address+offset, signedbv_typet(16)));
762+
from_integer(address+offset, unsignedbv_typet(16)));
761763
}
762764
address+=2;
763765
break;
764766

765767
case 'O': // four byte branch offset, signed
766768
{
767769
s4 offset=read_u4();
770+
// By converting the signed offset into an absolute address (by adding
771+
// the current address) the number represented becomes unsigned.
768772
instruction.args.push_back(
769-
from_integer(address+offset, signedbv_typet(32)));
773+
from_integer(address+offset, unsignedbv_typet(32)));
770774
}
771775
address+=4;
772776
break;
@@ -820,8 +824,10 @@ void java_bytecode_parsert::rbytecode(
820824

821825
// now default value
822826
s4 default_value=read_u4();
827+
// By converting the signed offset into an absolute address (by adding
828+
// the current address) the number represented becomes unsigned.
823829
instruction.args.push_back(
824-
from_integer(base_offset+default_value, signedbv_typet(32)));
830+
from_integer(base_offset+default_value, unsignedbv_typet(32)));
825831
address+=4;
826832

827833
// number of pairs
@@ -834,8 +840,10 @@ void java_bytecode_parsert::rbytecode(
834840
s4 offset=read_u4();
835841
instruction.args.push_back(
836842
from_integer(match, signedbv_typet(32)));
843+
// By converting the signed offset into an absolute address (by adding
844+
// the current address) the number represented becomes unsigned.
837845
instruction.args.push_back(
838-
from_integer(base_offset+offset, signedbv_typet(32)));
846+
from_integer(base_offset+offset, unsignedbv_typet(32)));
839847
address+=8;
840848
}
841849
}
@@ -867,8 +875,10 @@ void java_bytecode_parsert::rbytecode(
867875
{
868876
s4 offset=read_u4();
869877
instruction.args.push_back(from_integer(i, signedbv_typet(32)));
878+
// By converting the signed offset into an absolute address (by adding
879+
// the current address) the number represented becomes unsigned.
870880
instruction.args.push_back(
871-
from_integer(base_offset+offset, signedbv_typet(32)));
881+
from_integer(base_offset+offset, unsignedbv_typet(32)));
872882
address+=4;
873883
}
874884
}

0 commit comments

Comments
 (0)