From dc47cb9d199fc0a1eb48496e245d095e62cd79e6 Mon Sep 17 00:00:00 2001 From: Osvaldo Janeri Filho Date: Sat, 14 Nov 2026 22:15:18 -0300 Subject: [PATCH] load_it: fix unsigned underflow in the IT pattern command bounds check 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. --- src/load_it.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/load_it.cpp b/src/load_it.cpp index 0a72dff..348dc1c 100644 --- a/src/load_it.cpp +++ b/src/load_it.cpp @@ -553,7 +553,7 @@ BOOL CSoundFile::ReadIT(const BYTE *lpStream, DWORD dwMemLength) // Reading command/param if (chnmask[ch] & 8) { - if (i > len - 2) break; + if (i + 1 >= len) break; UINT cmd = p[i++]; UINT param = p[i++]; if (ch < m_nChannels)