Skip to content

Fix integer underflow reading undersized rtp/sdp atoms - #100

Open
1820893135-pixel wants to merge 1 commit into
TechSmith:mainfrom
1820893135-pixel:fix-rtp-sdp-atom-size-underflow
Open

Fix integer underflow reading undersized rtp/sdp atoms#100
1820893135-pixel wants to merge 1 commit into
TechSmith:mainfrom
1820893135-pixel:fix-rtp-sdp-atom-size-underflow

Conversation

@1820893135-pixel

Copy link
Copy Markdown

Fixes the integer underflow reported in #98.

Root cause

MP4RtpAtom::ReadHntiType() (and identically MP4SdpAtom::Read()) computes the SDP string length as:

uint64_t size = GetEnd() - m_File.GetPosition();
char* data = (char*)MP4Malloc(size + 1);

If the rtp / sdp atom is declared so small (e.g. a size field that only covers the 8-byte header) that the read position has already passed the atom's declared end, the uint64_t subtraction underflows to a value close to 2^64. MP4Malloc(size + 1) then attempts a ~2^64-byte allocation and ASan aborts with allocation-size-too-big (requested 0xfffffffffffffffd).

Fix

Guard the position before computing the size; if it has reached/passed the atom's end, the atom is malformed — log a warning and skip the SDP read (the caller already Skip()s to the end of the atom).

Verified: the reproducer from #98 aborts with allocation-size-too-big on the unfixed build and parses cleanly (exit 0, no sanitizer report) with this change under -fsanitize=address,undefined -fno-sanitize-recover=all.

Fixes #98.

MP4RtpAtom::ReadHntiType() and MP4SdpAtom::Read() compute the string
length as GetEnd() - m_File.GetPosition() and pass it straight to
MP4Malloc(). If the atom is declared so small that the read position
has already passed its declared end, the subtraction underflows to a
value close to 2^64 and MP4Malloc() attempts a ~2^64-byte allocation
(ASan: allocation-size-too-big). Guard the position before computing the
size and skip the read (the atom is malformed) instead.

Fixes TechSmith#98.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant