Skip to content

tag: bound picture-data allocation in readPictureBlock - #115

Open
ChrisJr404 wants to merge 1 commit into
dhowden:masterfrom
ChrisJr404:fix-vorbis-picture-alloc
Open

ChrisJr404 wants to merge 1 commit into
dhowden:masterfrom
ChrisJr404:fix-vorbis-picture-alloc

Conversation

@ChrisJr404

Copy link
Copy Markdown

While reading a FLAC/Vorbis PICTURE block, readPictureBlock takes the 4-byte picture-data length directly from the file and then does data := make([]byte, dataLen) before reading any of it. That path bypasses the readBytesMaxUpfront (10 MB) cap that the rest of the package already uses via readBytes, so an attacker-controlled length is trusted verbatim.

Failure mode: a malformed FLAC or Ogg/Vorbis file (or a metadata_block_picture comment) only a few dozen bytes long can advertise a multi-gigabyte picture and force ReadFrom into a correspondingly huge allocation — a memory-amplification DoS for any caller reading untrusted files.

Repro (before this change): a 40-byte fLaC file whose single metadata block is a PICTURE block declaring a 100 MiB data length makes ReadFrom allocate 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; gofmt and go vet are clean.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant