Repository navigation
Fix for CVE-2026-111271 - OOB read in CSoundFile::ReadAMS2() - #107
Merged
Merged
Conversation
The pattern unpack loop in CSoundFile::ReadAMS2() tests "pos < packedlen"
only at the top of each iteration, but the body advances pos up to five
times. The inner effect loop is the worst of them:
while (byte2 & 0x80)
{
byte2 = psrc[pos++];
...
UINT param = psrc[pos++];
It runs for as long as every byte it fetches has bit 7 set, with no bound
of its own, so a pattern whose effect bytes all keep bit 7 set walks pos
past packedlen and on past the end of the input buffer, reading adjacent
heap memory until it finds a byte without bit 7 or hits an unmapped page.
Check pos against packedlen at each read instead. packedlen already
satisfies packedlen < dwMemLength - dwMemPos, so staying within it keeps
every read inside the buffer.
This is the v2 counterpart of upstream 70d73b9, which added exactly this
bound to the four reads in the ReadAMS() v1 decoder and left ReadAMS2()
alone. The "pos+1 > packedlen" spelling is upstream's from that commit.
The two byte note/instrument read just above has the same problem on a
smaller scale and is bounded here too.
The first hunk fixes a problem not described in the CVE: the pattern name
memcpy reads patnamlen bytes from dwMemPos+3, with patnamlen up to
MAX_PATTERNNAME-1, but at that point only dwMemPos+4 is known to be inside
the buffer, so a pattern at the end of the file reads up to 30 bytes past
it. The dwMemPos checks added previously do not cover this: they all sit
in the instrument and sample loops, which finish before the pattern section
starts.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The pattern unpack loop in CSoundFile::ReadAMS2() tests "pos < packedlen"
only at the top of each iteration, but the body advances pos up to five
times. The inner effect loop is the worst of them:
It runs for as long as every byte it fetches has bit 7 set, with no bound
of its own, so a pattern whose effect bytes all keep bit 7 set walks pos
past packedlen and on past the end of the input buffer, reading adjacent
heap memory until it finds a byte without bit 7 or hits an unmapped page.
Check pos against packedlen at each read instead. packedlen already
satisfies packedlen < dwMemLength - dwMemPos, so staying within it keeps
every read inside the buffer.
This is the v2 counterpart of upstream 70d73b9, which added exactly this
bound to the four reads in the ReadAMS() v1 decoder and left ReadAMS2()
alone. The "pos+1 > packedlen" spelling is upstream's from that commit.
The two byte note/instrument read just above has the same problem on a
smaller scale and is bounded here too.
The first hunk fixes a problem not described in the CVE: the pattern name
memcpy reads patnamlen bytes from dwMemPos+3, with patnamlen up to
MAX_PATTERNNAME-1, but at that point only dwMemPos+4 is known to be inside
the buffer, so a pattern at the end of the file reads up to 30 bytes past
it. The dwMemPos checks added previously do not cover this: they all sit
in the instrument and sample loops, which finish before the pattern section
starts.
Co-Authored-By: Claude Opus 5 noreply@anthropic.com