REDHAT-BUG-2576238: Buffer Overflow
A stack-based buffer overflow (CWE-121) was found in the flac command-line encoder. When flac re-encodes a FLAC (or Ogg-FLAC) input, the decoder callback stores each metadata block of the input into the fixed-size, on-stack array FLACDecoderData.metadatablocks[1024], embedded in the EncoderSession object (a stack local of flacencodefile, src/flac/encode.c:862). The callback rejects inputs carrying more than 1024 blocks, so an input with exactly 1024 blocks fills the array completely. EncoderSessioninitencoder() then appends one metadata clone per --picture option to that same array with no bound check (flac 1.4.3: src/flac/encode.c:1677-1685) -- the only writer into the array without one; the vorbis-comment (1715), cuesheet (1773), seektable (1830) and padding (1879) writers all carry a nummetadatablocks < sizeof(metadatablocks)/sizeof(metadatablocks[0]) guard.
Overflow condition: inputblocks + pictures > 1024 (with the 64-picture cap, any input with >= 963 blocks suffices). The out-of-bounds stores write heap pointers (FLACmetadataobjectclone results) over consecutive EncoderSession fields: index 1024 -> sampleslefttoprocess, 1025 -> fatalerror, 1026 -> encoder (FLACStreamEncoder), then fin, seektabletemplate, progress, compressionratio; the object ends at index 1032. Once the encoder field is clobbered (3rd --picture option), the first FLACstreamencoder call dereferences a picture clone as an encoder and faults.
Only the FLAC/Ogg-FLAC input path is affected; WAV/AIFF input uses a heap-growing list. metaflac and libFLAC API consumers are not affected (the array is CLI-local).
Reproduced on flac-1.4.3-6.el10 (RHEL 10 package set) with a crafted valid FLAC file (1024 metadata blocks: STREAMINFO + VORBISCOMMENT + 1022 zero-length PADDING, passes flac -t): - Stock release binary: 1 --picture option -> clean encode; 2 -> graceful error abort; >= 3 -> SIGSEGV (exit 139). - libasan rebuild from RPM source, 8 options: AddressSanitizer stack-buffer-overflow, WRITE of size 8 in EncoderSessioninitencoder, addr2line-resolved to the unguarded append at src/flac/encode.c:1684, overflowing the encodersession stack object. - valgrind on the stock binary: invalid read at address 0x6 in FLACstreamencodersetverify -- the clobbered encoder field holds a picture clone (FLACMETADATATYPEPICTURE == 6), independently confirming the store hit the encoder field.
Demonstrated impact is a crash of the encoding process; the written values are heap pointers to clones of the victim's own --picture specifications, not attacker-chosen data, and code execution was not demonstrated (512-byte overrun cap, PIE/RELRO/NX).
Affected versions: the unguarded append is present in flac 1.3.2 (encode.c:1826), 1.3.3 (1825), 1.4.3 (1684) and 1.5.0/master (1717) -- i.e. the versions shipped in RHEL 8, 9 and 10 -- with no dist-git patch covering it. No CVE currently covers this issue.
Suggested fix: bound the append as the sibling writers do (reject or stop once nummetadatablocks reaches sizeof(metadatablocks)/sizeof(metadatablocks[0])); replacing the fixed 1024-entry array with a dynamically grown list is the larger cleanup flagged by the upstream BAD MAGIC number comment.
CVSS 3.1: AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H (5.5 Medium).
Reported by Calif.io (ANT-2026-XEY70RK0) via the Product Security support portal (PSIRTSUPT-30538); analysis artifacts in the ticket directory PSIRTSUPT-30538flac-bof.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
In the flac command-line encoder, bound the --picture metadata append: reject or stop appending when num_metadata_blocks reaches sizeof(metadata_blocks)/sizeof(metadata_blocks[0]).