Skip to content

Commit

Permalink
decode: Fix UB for shift of negative offset
Browse files Browse the repository at this point in the history
Fixes #12.
  • Loading branch information
aengelke committed Dec 13, 2024
1 parent c9c107e commit 1c708f1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ fd_decode(const uint8_t* buffer, size_t len_sz, int mode_int, uintptr_t address,
if (op_byte & 0x40) {
if (UNLIKELY((off += 1) > len))
return FD_ERR_PARTIAL;
instr->disp = (int8_t) LOAD_LE_1(dispbase) << dispscale;
instr->disp = (int8_t) LOAD_LE_1(dispbase) * (1 << dispscale);
} else if (op_byte & 0x80 || (op_byte & 0xc7) == 0x06) {
if (UNLIKELY((off += 2) > len))
return FD_ERR_PARTIAL;
Expand Down Expand Up @@ -578,7 +578,7 @@ fd_decode(const uint8_t* buffer, size_t len_sz, int mode_int, uintptr_t address,
if (op_byte & 0x40) {
if (UNLIKELY((off += 1) > len))
return FD_ERR_PARTIAL;
instr->disp = (int8_t) LOAD_LE_1(dispbase) << dispscale;
instr->disp = (int8_t) LOAD_LE_1(dispbase) * (1 << dispscale);
} else if (op_byte & 0x80 || (op_byte < 0x40 && base == 5)) {
if (UNLIKELY((off += 4) > len))
return FD_ERR_PARTIAL;
Expand Down

0 comments on commit 1c708f1

Please sign in to comment.