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 <mikispag@google.com>
diff --git a/examples/c/decode/file/main.c b/examples/c/decode/file/main.c
index ff2b145..21056fa 100644
--- a/examples/c/decode/file/main.c
+++ b/examples/c/decode/file/main.c
@@ -125,6 +125,18 @@
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) {