X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fvp3.c;h=0cae07545233412634d1a6a4cdecdbec376c44af;hb=a247ac640df3da573cd661065bf53f37863e2b46;hp=2f43de757ed470a58953f693bf0c56c0bcdfaa7d;hpb=802fc678b262ea5d3523169184a9ec9503bf7807;p=ffmpeg diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index 2f43de757ed..0cae0754523 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -35,6 +35,7 @@ #include #include "libavutil/imgutils.h" +#include "libavutil/mem_internal.h" #include "avcodec.h" #include "get_bits.h" @@ -2319,20 +2320,6 @@ static av_cold int init_frames(Vp3DecodeContext *s) return 0; } -static av_cold int theora_init_huffman_tables(VLC *vlc, const HuffTable *huff) -{ - uint32_t code = 0, codes[32]; - - for (unsigned i = 0; i < huff->nb_entries; i++) { - codes[i] = code >> (31 - huff->entries[i].len); - code += 0x80000000U >> huff->entries[i].len; - } - return ff_init_vlc_sparse(vlc, 11, huff->nb_entries, - &huff->entries[0].len, sizeof(huff->entries[0]), 1, - codes, 4, 4, - &huff->entries[0].sym, sizeof(huff->entries[0]), 1, 0); -} - static av_cold int vp3_decode_init(AVCodecContext *avctx) { Vp3DecodeContext *s = avctx->priv_data; @@ -2460,7 +2447,12 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx) } } else { for (i = 0; i < FF_ARRAY_ELEMS(s->coeff_vlc); i++) { - ret = theora_init_huffman_tables(&s->coeff_vlc[i], &s->huffman_table[i]); + const HuffTable *tab = &s->huffman_table[i]; + + ret = ff_init_vlc_from_lengths(&s->coeff_vlc[i], 11, tab->nb_entries, + &tab->entries[0].len, sizeof(*tab->entries), + &tab->entries[0].sym, sizeof(*tab->entries), 1, + 0, 0, avctx); if (ret < 0) return ret; } @@ -2883,6 +2875,9 @@ static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb) int ret; AVRational fps, aspect; + if (get_bits_left(gb) < 206) + return AVERROR_INVALIDDATA; + s->theora_header = 0; s->theora = get_bits(gb, 24); av_log(avctx, AV_LOG_DEBUG, "Theora bitstream version %X\n", s->theora); @@ -3164,7 +3159,7 @@ static av_cold int theora_decode_init(AVCodecContext *avctx) return vp3_decode_init(avctx); } -AVCodec ff_theora_decoder = { +const AVCodec ff_theora_decoder = { .name = "theora", .long_name = NULL_IF_CONFIG_SMALL("Theora"), .type = AVMEDIA_TYPE_VIDEO, @@ -3182,7 +3177,7 @@ AVCodec ff_theora_decoder = { }; #endif -AVCodec ff_vp3_decoder = { +const AVCodec ff_vp3_decoder = { .name = "vp3", .long_name = NULL_IF_CONFIG_SMALL("On2 VP3"), .type = AVMEDIA_TYPE_VIDEO, @@ -3199,7 +3194,7 @@ AVCodec ff_vp3_decoder = { }; #if CONFIG_VP4_DECODER -AVCodec ff_vp4_decoder = { +const AVCodec ff_vp4_decoder = { .name = "vp4", .long_name = NULL_IF_CONFIG_SMALL("On2 VP4"), .type = AVMEDIA_TYPE_VIDEO,