]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/flac_parser.c
qsv: Load the hw hevc plugin by default on Linux
[ffmpeg] / libavcodec / flac_parser.c
index bf2c11821b197cce509b610f8fef03604a96c898..8150ec4d1131407b174b79bc3fd0f2125d70a8bd 100644 (file)
@@ -92,9 +92,9 @@ typedef struct FLACParseContext {
 static int frame_header_is_valid(AVCodecContext *avctx, const uint8_t *buf,
                                  FLACFrameInfo *fi)
 {
-    GetBitContext gb;
-    init_get_bits(&gb, buf, MAX_FRAME_HEADER_SIZE * 8);
-    return !ff_flac_decode_frame_header(avctx, &gb, fi, 127);
+    BitstreamContext bc;
+    bitstream_init8(&bc, buf, MAX_FRAME_HEADER_SIZE);
+    return !ff_flac_decode_frame_header(avctx, &bc, fi, 127);
 }
 
 /**
@@ -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) {
@@ -579,7 +588,7 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
                                   read_end - read_start, NULL);
         } else {
             int8_t pad[MAX_FRAME_HEADER_SIZE] = { 0 };
-            av_fifo_generic_write(fpc->fifo_buf, (void*) pad, sizeof(pad), NULL);
+            av_fifo_generic_write(fpc->fifo_buf, pad, sizeof(pad), NULL);
         }
 
         /* Tag headers and update sequences. */