]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/hcom.c
avcodec: Constify AVCodecs
[ffmpeg] / libavcodec / hcom.c
index aab1001dd28ab68c6940186461a44545668227d5..1c49988b3a0dd308e10a7353e4ca7ad3dae7b6b1 100644 (file)
@@ -52,7 +52,8 @@ static av_cold int hcom_init(AVCodecContext *avctx)
     if (avctx->extradata_size <= 7)
         return AVERROR_INVALIDDATA;
     s->dict_entries = AV_RB16(avctx->extradata);
-    if (avctx->extradata_size < s->dict_entries * 4 + 7)
+    if (avctx->extradata_size < s->dict_entries * 4 + 7 ||
+        s->dict_entries == 0)
         return AVERROR_INVALIDDATA;
     s->delta_compression = AV_RB32(avctx->extradata + 2);
     s->sample = s->first_sample = avctx->extradata[avctx->extradata_size - 1];
@@ -63,7 +64,14 @@ static av_cold int hcom_init(AVCodecContext *avctx)
     for (int i = 0; i < s->dict_entries; i++) {
         s->dict[i].l = AV_RB16(avctx->extradata + 6 + 4 * i);
         s->dict[i].r = AV_RB16(avctx->extradata + 6 + 4 * i + 2);
+        if (s->dict[i].l >= 0 &&
+            (s->dict[i].l >= s->dict_entries ||
+             s->dict[i].r >= s->dict_entries ||
+             s->dict[i].r < 0 ))
+            return AVERROR_INVALIDDATA;
     }
+    if (s->dict[0].l < 0)
+        return AVERROR_INVALIDDATA;
 
     avctx->sample_fmt = AV_SAMPLE_FMT_U8;
     s->dict_entry = 0;
@@ -90,11 +98,10 @@ static int hcom_decode(AVCodecContext *avctx, void *data,
         return ret;
 
     while (get_bits_left(&gb) > 0) {
-        if (get_bits1(&gb)) {
+        if (get_bits1(&gb))
             s->dict_entry = s->dict[s->dict_entry].r;
-        } else {
+        else
             s->dict_entry = s->dict[s->dict_entry].l;
-        }
 
         if (s->dict[s->dict_entry].l < 0) {
             int16_t datum;
@@ -127,7 +134,7 @@ static av_cold int hcom_close(AVCodecContext *avctx)
     return 0;
 }
 
-AVCodec ff_hcom_decoder = {
+const AVCodec ff_hcom_decoder = {
     .name           = "hcom",
     .long_name      = NULL_IF_CONFIG_SMALL("HCOM Audio"),
     .type           = AVMEDIA_TYPE_AUDIO,
@@ -137,4 +144,5 @@ AVCodec ff_hcom_decoder = {
     .close          = hcom_close,
     .decode         = hcom_decode,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };