From: <sv...@op...> - 2024-11-24 12:58:08
|
Author: sagamusix Date: Sun Nov 24 13:58:01 2024 New Revision: 22283 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22283 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.31/ (props changed) branches/OpenMPT-1.31/soundlib/ContainerMMCMP.cpp Modified: branches/OpenMPT-1.31/soundlib/ContainerMMCMP.cpp ============================================================================== --- branches/OpenMPT-1.31/soundlib/ContainerMMCMP.cpp Sun Nov 24 13:53:45 2024 (r22282) +++ branches/OpenMPT-1.31/soundlib/ContainerMMCMP.cpp Sun Nov 24 13:58:01 2024 (r22283) @@ -231,6 +231,7 @@ #ifdef MMCMP_LOG MPT_LOG_GLOBAL(LogDebug, "MMCMP", MPT_UFORMAT(" 16-bit block: pos={} size={} {} {}")(psubblk->position, psubblk->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) }; @@ -316,6 +317,7 @@ uint32 numbits = blk.num_bits; uint32 oldval = 0; if(blk.tt_entries > sizeof(ptable) + || numbits > 7 || !file.Seek(memPos) || file.ReadRaw(mpt::span(ptable, blk.tt_entries)).size() < blk.tt_entries) return false; |