From: <sv...@op...> - 2024-11-24 12:58:46
|
Author: sagamusix Date: Sun Nov 24 13:58:39 2024 New Revision: 22285 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22285 Log: Merged revision(s) 22227 from trunk/OpenMPT: [Fix] MMCMP: Avoid undefined shift behaviour when trying to read an arbitrary number of bits. Reject such malformed files like Ancient does. ........ Modified: branches/OpenMPT-1.29/ (props changed) branches/OpenMPT-1.29/soundlib/ContainerMMCMP.cpp Modified: branches/OpenMPT-1.29/soundlib/ContainerMMCMP.cpp ============================================================================== --- branches/OpenMPT-1.29/soundlib/ContainerMMCMP.cpp Sun Nov 24 13:58:19 2024 (r22284) +++ branches/OpenMPT-1.29/soundlib/ContainerMMCMP.cpp Sun Nov 24 13:58:39 2024 (r22285) @@ -263,6 +263,7 @@ #ifdef MMCMP_LOG MPT_LOG(LogDebug, "MMCMP", mpt::format(U_(" 16-bit block: pos=%1 size=%2 %3 %4"))(psubblk->unpk_pos, psubblk->unpk_size, (blk.flags & MMCMP_DELTA) ? U_("DELTA ") : U_(""), (blk.flags & MMCMP_ABS16) ? U_("ABS16 ") : U_(""))); #endif + if(numbits > 15) return false; if(!file.Seek(memPos + blk.tt_entries)) return false; if(!file.CanRead(blk.pk_size - blk.tt_entries)) return false; BitReader bitFile{ file.GetChunk(blk.pk_size - blk.tt_entries) }; @@ -340,6 +341,7 @@ uint32 numbits = blk.num_bits; uint32 oldval = 0; if(blk.tt_entries > sizeof(ptable) + || numbits > 7 || !file.Seek(memPos) || file.ReadRaw(ptable, blk.tt_entries) < blk.tt_entries) return false; |