flacenc: Correctly handle up to 255 cue entries
authorSebastian Dröge <sebastian@centricular.com>
Thu, 28 Sep 2023 15:03:31 +0000 (18:03 +0300)
committerTim-Philipp Müller <tim@centricular.com>
Wed, 4 Oct 2023 18:06:33 +0000 (19:06 +0100)
commit10d42caef22327a77a47222fc6aa4b6b091fcb61
tree94117c33c04df59b83ef352c8c53bca4b6be1485
parent4311de2be0d66132555388570c15d5de6c2a47f3
flacenc: Correctly handle up to 255 cue entries

The counter was using a signed 8 bit integer, which was overflowing
after 127 entries. That was then passed as an unsigned 32 bit integer to
libflac, which caused it to be converted to a huge unsigned number.
That then caused an invalid memory access inside libflac.

As a bonus, signed integer overflow is undefined behaviour.

Instead, use an unsigned 8 bit integer. Once this overflows the existing
code already catches it and stops adding the cue. While FLAC__metadata_object_cuesheet_insert_track()
takes an unsigned 32 bit integer for the track number, FLAC__StreamMetadata_CueSheet_Track is
limiting it to an unsigned 8 bit integer.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2921

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5436>
subprojects/gst-plugins-good/ext/flac/gstflacenc.c