From 93846ee22383fae4a57dc467022524d9d828694a Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Thu, 20 Nov 2014 21:19:36 +1100 Subject: [PATCH] examples/c/decode/file/main.c : Add extra error handling. Michele Spagnuolo provided a file that initially had frames with two channels but then had a frame with a single channel. This example program only supports exactly two channels and previously had insufficient validation. Closes: https://sourceforge.net/p/flac/bugs/418/ Reported-by: Michele Spagnuolo, Google Security Team --- examples/c/decode/file/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/c/decode/file/main.c b/examples/c/decode/file/main.c index ff2b1455..21056fa5 100644 --- a/examples/c/decode/file/main.c +++ b/examples/c/decode/file/main.c @@ -125,6 +125,18 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder fprintf(stderr, "ERROR: this example only supports 16bit stereo streams\n"); return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; } + if(frame->header.channels != 2) { + fprintf(stderr, "ERROR: This frame contains %d channels (should be 2)\n", frame->header.channels); + return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; + } + if(buffer [0] == NULL) { + fprintf(stderr, "ERROR: buffer [0] is NULL\n"); + return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; + } + if(buffer [1] == NULL) { + fprintf(stderr, "ERROR: buffer [1] is NULL\n"); + return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; + } /* write WAVE header before we write the first frame */ if(frame->header.number.sample_number == 0) {