]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/flac_parser.c
Merge commit '06f4b1e37a08f3fd269ecbfeb0181129e5bfc86e'
[ffmpeg] / libavcodec / flac_parser.c
index 12e09bb55e0b108f727c9abe120a07ba459abbda..372371644199bdc0a38dcd73047f14b7d64a2117 100644 (file)
@@ -615,6 +615,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_space(fpc->fifo_buf) < read_end - read_start
             && av_fifo_realloc2(fpc->fifo_buf, (read_end - read_start) + 2*av_fifo_size(fpc->fifo_buf)) < 0) {