Commit 033af7bf authored by Erik de Castro Lopo's avatar Erik de Castro Lopo
Browse files

libFLAC : Put upper bound on number of seek points.

Restrict number of seek points to 32768 total and a maximum of two per
second.

Ten hours of content is 36000 seconds which gives about one seek point
for every second for those ten hours. Also, having more than two seek
point per second makes little sense regardless of content length.

Without these restrictions flac-to-flac encoding of a malformed input
file (eg something generated with http://lcamtuf.coredump.cx/afl/)
can result in an attempt to generate a stupidly large number of seek
points and cause an allocation failure.
parent c06a4496
......@@ -1128,6 +1128,13 @@ FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_point
if(total_samples % samples == 0)
num--;
/* Put a strict upper bound on he number of allows seekpoints. */
if (num > 32768) {
/* Set the bound and recalculate samples accordingly. */
num = 32786;
samples = total_samples / num;
}
i = seek_table->num_points;
if(!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + (unsigned)num))
......
......@@ -69,6 +69,8 @@ FLAC__bool grabbag__seektable_convert_specification_to_template(const char *spec
const double sec = atof(pt);
if(sec > 0.0) {
unsigned samples = (unsigned)(sec * (double)sample_rate);
/* Restrict seekpoints to two per second of audio. */
samples = samples < sample_rate / 2 ? sample_rate / 2 : samples;
if(samples > 0) {
/* +1 for the initial point at sample 0 */
if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(seektable_template, samples, total_samples_to_encode))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment