OSDN Git Service

flac: fix realloc loop with invalid flac files
authorThomas Guillem <thomas@gllm.fr>
Thu, 16 Apr 2015 16:33:31 +0000 (18:33 +0200)
committerLuca Barbato <lu_zero@gentoo.org>
Mon, 20 Apr 2015 10:41:33 +0000 (12:41 +0200)
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
libavcodec/flac_parser.c

index bf2c118..70b9a65 100644 (file)
@@ -565,6 +565,15 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
                                               nb_desired * FLAC_AVG_FRAME_SIZE);
         }
 
+        if (!av_fifo_space(fpc->fifo_buf) &&
+            av_fifo_size(fpc->fifo_buf) / FLAC_AVG_FRAME_SIZE >
+            fpc->nb_headers_buffered * 10) {
+            /* There is less than one valid flac header buffered for 10 headers
+             * buffered. Therefore the fifo is most likely filled with invalid
+             * data and the input is not a flac file. */
+            goto handle_error;
+        }
+
         /* Fill the buffer. */
         if (av_fifo_realloc2(fpc->fifo_buf,
                              (read_end - read_start) + av_fifo_size(fpc->fifo_buf)) < 0) {