From: <sv...@op...> - 2024-11-18 21:36:04
|
Author: sagamusix Date: Mon Nov 18 22:35:52 2024 New Revision: 22230 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22230 Log: [Fix] Avoid integer wraparound when period + fractional period exceeds 32-bit integer limits. Found with afl++ + ubsan. Modified: trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/soundlib/Sndmix.cpp ============================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp Mon Nov 18 22:27:12 2024 (r22229) +++ trunk/OpenMPT/soundlib/Sndmix.cpp Mon Nov 18 22:35:52 2024 (r22230) @@ -1839,8 +1839,15 @@ vdelta += Util::muldiv(period, fineUpTable[l & 0x03], 0x10000) - period; } } - period = (period + vdelta) / 256; - nPeriodFrac = vdelta & 0xFF; + if(Util::MaxValueOfType(period) - period >= vdelta) + { + period = (period + vdelta) / 256; + nPeriodFrac = vdelta & 0xFF; + } else + { + period = Util::MaxValueOfType(period) / 256; + nPeriodFrac = 0; + } } else { // MPT's autovibrato code |