ogg_stream_pagein: validate page segment table against body length - #108
Open
XananasX7 wants to merge 8 commits into
Open
ogg_stream_pagein: validate page segment table against body length#108XananasX7 wants to merge 8 commits into
XananasX7 wants to merge 8 commits into
Conversation
Found with codespell.
Checksums of the source packages, produced by the gitlab ci runner, as published to https://downloads.xiph.org/releases/ogg/SHA256SUMS.
Remove the obsolete Travis and Jenkins continuous integration status badges from the README and add ones for Gitlab and Github.
The opus website no longer references libogg, and we publish directly to ftp these days without going through svn.
Add some newer files generated by the autotools build to the git ignore list so they don't clutter up status output or end up accidentally included in a commit to the repository.
Support for earlier versions is deprecated. Addresses a deprecation warning building with recent cmake versions. Signed-off-by: Ralph Giles <giles@thaumas.net>
The original commit from 2007 (440e37e) accumulated all sizes in ints (despite ogg_iovec_t.iov_len being a size_t and all relevant fields of ogg_stream_state being longs). I expanded this to longs in 2013 when I added overflow checks (commit 85dbd8d), but apparently did not read far enough down in the function to catch this cast back to int the second time the sizes are accumulated. Patch from: Chengyu Song <csong@ucr.edu> Fixes #2308.
ogg_stream_pagein() is a public entry point and may be handed pages that were parsed or constructed by the caller (custom demuxers, remuxers, seek/index layers, or sync builds with DISABLE_CRC). Pages produced by ogg_sync_pageout() are length- and checksum-verified, but callers using their own page parsing can supply an ogg_page whose segment table claims more body data than body_len contains. In that case bodysize went negative when the segment table was walked: the continued-packet skip loop (or a final short body) then reached a memcpy with a negative length (huge size_t), or left body_fill negative for subsequent packet assembly -- a heap-corruption / out-of-bounds condition reachable from malformed media. Reject any page whose lacing values overshoot its body (or whose header_len can't contain the segment table), before trusting the table, returning -1 as with other invalid pages. Tested: malformed pages now return -1 (previously ASan reported 'negative-size-param' in memcpy); a full encode/decode round trip, including packets spanning multiple 255-lacing segments and BOS/EOS flags, decodes identically to before.
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.
Problem
ogg_stream_pagein()is a public entry point and may be handed pages that were parsed or constructed by the caller (custom demuxers, remuxers, seek/index layers, or sync builds withDISABLE_CRC). Pages produced byogg_sync_pageout()are length- and checksum-verified, but callers using their own page parsing can supply anogg_pagewhose segment table claims more body data thanbody_lencontains.In that case
bodysizegoes negative while the segment table is walked: the continued-packet skip loop (or a final short body) then reachesmemcpywith a negative length (hugesize_t), or leavesbody_fillnegative for subsequent packet assembly — a heap-corruption / out-of-bounds condition reachable from malformed media. ASan reportsnegative-size-paramatframing.c:862.Minimal reproducer against current master:
Fix
Reject any page whose lacing values overshoot its body (or whose
header_lencan't contain the segment table) before trusting the table, returning-1as with other invalid pages. The check is O(segments) with an early exit, and validates pages produced byogg_sync_pageout()(which satisfy it by construction).Testing
-1(previously: ASannegative-size-paraminmemcpy).