flacparse: large padding headers cause high memory consumption
Submitted by Carlos Rafael Giani
Assigned to Reynaldo H. Verdejo Pinochet
Link to original bug (#759778)
Description
Some FLAC files have large padding headers. According to the FLAC spec, padding headers do not contain valid data and mainly exist as a reserve space for future metadata modifications/additions. Yet, flacparse accumulates incoming buffers until all headers are parsed, including padding headers, and then feeds all this data in one go to downstream. As a result, playback can take considerably longer to start, especially on embedded devices. Memory usage also greatly increases, and can lead to out-of-memory errors on such devices. It would be good if flacparse ignores/discards padding headers and not feed them to downstream. Better yet, since the size of the header is known from the start, just skip it entirely (at least in pull mode).
Test files can be generated with the following gst-launch line:
gst-launch-1.0 audiotestsrc wave=sine num-buffers=30 samplesperbuffer=44100 ! "audio/x-raw, rate=44100, channels=2" ! flacenc padding=16777215 ! filesink location=test-padding.flac
Note the padding=16777215 property. 16777215 is the maximum size flacenc will allow for a padding block. Values larger than that cause libflac to apply padding in a different, undetermined way.