Repository navigation
Conversation
The two-byte command/param read in the IT pattern loop is guarded by `if (i > len - 2) break;`. len is a UINT read from the file (READ_LE16, 0..65535) and can be 0 or 1; then len - 2 underflows to a huge unsigned value, the check never fires, and the following p[i++]/p[i++] read past the end of the pattern data. Every other read in the loop uses the safe `if (i >= len) break;` form. Use an addition that cannot underflow.
|
The existing code doesn't OOB read, for len == 0, L 468 prevents len = 0, and for len=1, L 480 will break. |
|
Yeah, you’re right. Traced it again and it can’t reach that read with len <
2.
len==0 breaks at L468 before any read. For len==1, hitting the chnmask[ch]
& 8 branch needs bit 8 already set, but chnmask is memset to 0 and only
gets assigned at L481, which is behind the L480 i >= len break (fires at
i==1==len). So it never gets there. len>=2 makes len-2 fine anyway.
So no OOB, the underflow’s dead code. I’ll close the PR. The i+1 >= len
form only buys you avoiding the underflow for readability, not worth
keeping if you’d rather not. Thanks for looking.
Osvaldo Janeri
… Message ID: ***@***.***>
|
|
Yeah, you're right. Traced it again and it can't reach that read with len < 2. len==0 breaks at L468 before any read. For len==1, hitting the So no OOB, the underflow's dead code. Closing this. The |
|
It could be good to clean up the code for readability / prevent future flagging. Just not marking it as an OOB read |
The IT pattern reader's two-byte command/param read is guarded by
if (i > len - 2) break;(src/load_it.cpp).lenis aUINTread fromthe file via
READ_LE16(0..65535) and can be 0 or 1. Whenlen < 2,len - 2underflows to a huge unsigned value, so the check never breaks andthe following
p[i++]/p[i++]read past the end of the pattern data (and,near the buffer end, past the module buffer).
Every other read in the same loop uses
if (i >= len) break;— this is the onesite that doesn't. A crafted
.itfile with a pattern length < 2 and a channelcarrying the command mask bit reaches it.
The fix uses an addition that can't underflow, matching the intent (two bytes
must be available):
Still present on
masterand theoob_read_fixesbranch — it wasn't covered bythe recent IT/OOB hardening, so sending it along.