Skip to content

Commit 1dbc8dc

Browse files
Rot127b1llow
andauthored
Fix UB of shift >63. (#2922)
* Fix UB of shift >63. Reported by https://github.com/sondt99 * Split size checks. Co-authored-by: billow <hoshinoaya@hoshinoaya.com>
1 parent d650f67 commit 1dbc8dc

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

arch/Xtensa/XtensaDisassembler.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ static DecodeStatus readInstruction32(MCInst *MI, const uint8_t *Bytes,
996996
}
997997

998998
/// Read InstSize bytes from the ArrayRef and return 24 bit data
999+
/// InstSize cannot be larger than 8.
9991000
static DecodeStatus readInstructionN(const uint8_t *Bytes, size_t BytesLen,
10001001
uint64_t Address, unsigned InstSize,
10011002
uint64_t *Size, uint64_t *Insn,
@@ -1006,6 +1007,9 @@ static DecodeStatus readInstructionN(const uint8_t *Bytes, size_t BytesLen,
10061007
*Size = 0;
10071008
return MCDisassembler_Fail;
10081009
}
1010+
if (InstSize > 8) {
1011+
InstSize = 8;
1012+
}
10091013

10101014
*Insn = 0;
10111015
for (unsigned i = 0; i < InstSize; i++)
@@ -1113,7 +1117,7 @@ static DecodeStatus getInstruction(MCInst *MI, uint64_t *Size,
11131117
if (Result != MCDisassembler_Fail)
11141118
return Result;
11151119

1116-
Result = readInstructionN(Bytes, BytesLen, Address, 48, Size,
1120+
Result = readInstructionN(Bytes, BytesLen, Address, 6, Size,
11171121
&Insn, IsLittleEndian);
11181122
if (Result == MCDisassembler_Fail)
11191123
return MCDisassembler_Fail;

0 commit comments

Comments
 (0)