tag: bound picture-data allocation in readPictureBlock - #115
Open
ChrisJr404 wants to merge 1 commit into
Open
ChrisJr404 wants to merge 1 commit into
ChrisJr404 wants to merge 1 commit into
Conversation
readPictureBlock read a 4-byte picture-data length straight from the file and then did make([]byte, dataLen) before reading, bypassing the readBytesMaxUpfront cap that the rest of the package uses. A malformed FLAC or Ogg/Vorbis file (or a metadata_block_picture comment) only a few dozen bytes long that advertises a multi-gigabyte picture therefore forces a correspondingly huge allocation, a memory-amplification DoS for anything running ReadFrom on untrusted input. Read the picture data through readBytes, which caps the up-front allocation and streams larger payloads. Valid files are unaffected.
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.
While reading a FLAC/Vorbis
PICTUREblock,readPictureBlocktakes the 4-byte picture-data length directly from the file and then doesdata := make([]byte, dataLen)before reading any of it. That path bypasses thereadBytesMaxUpfront(10 MB) cap that the rest of the package already uses viareadBytes, so an attacker-controlled length is trusted verbatim.Failure mode: a malformed FLAC or Ogg/Vorbis file (or a
metadata_block_picturecomment) only a few dozen bytes long can advertise a multi-gigabyte picture and forceReadFrominto a correspondingly huge allocation — a memory-amplification DoS for any caller reading untrusted files.Repro (before this change): a 40-byte
fLaCfile whose single metadata block is a PICTURE block declaring a 100 MiB data length makesReadFromallocate 100 MiB (and up to ~4 GiB with the maximum 32-bit length), even though no picture data follows.Fix: read the picture data through
readBytes, the same helper used elsewhere, which caps the up-front allocation and streams larger payloads instead of trusting the declared size. Valid files are unaffected.Tests: added
TestFLACPictureAllocationBounded, which decodes a tiny crafted FLAC and asserts the decode stays under 20 MiB (fails on the old code at 100 MiB, passes now). The existing test suite (which parses the real FLAC/Ogg fixtures with picture blocks) still passes;gofmtandgo vetare clean.