Skip to content

Commit

Permalink
[Fix] MMCMP: Avoid undefined shift behaviour when trying to read an a…
Browse files Browse the repository at this point in the history
…rbitrary number of bits. Reject such malformed files like Ancient does.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22227 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Nov 18, 2024
1 parent caae04c commit 21bda55
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions soundlib/ContainerMMCMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ bool UnpackMMCMP(std::vector<ContainerItem> &containerItems, FileReader &file, C
#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) };
Expand Down Expand Up @@ -316,6 +317,7 @@ bool UnpackMMCMP(std::vector<ContainerItem> &containerItems, FileReader &file, C
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;
Expand Down

0 comments on commit 21bda55

Please sign in to comment.