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);
}
/**
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) {
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. */