Browse code

alacdec: read/validate number of channels from the extradata.

check frame header channel count against header/container channel count.

Justin Ruggles authored on 2011/10/06 09:07:29
Showing 1 changed files
... ...
@@ -119,7 +119,7 @@ static int alac_set_info(ALACContext *alac)
119 119
     alac->setinfo_rice_historymult      = *ptr++;
120 120
     alac->setinfo_rice_initialhistory   = *ptr++;
121 121
     alac->setinfo_rice_kmodifier        = *ptr++;
122
-    ptr++;                         /* channels? */
122
+    alac->numchannels                   = *ptr++;
123 123
     bytestream_get_be16(&ptr);      /* ??? */
124 124
     bytestream_get_be32(&ptr);      /* max coded frame size */
125 125
     bytestream_get_be32(&ptr);      /* bitrate ? */
... ...
@@ -456,10 +456,9 @@ static int alac_decode_frame(AVCodecContext *avctx,
456 456
     init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8);
457 457
 
458 458
     channels = get_bits(&alac->gb, 3) + 1;
459
-    if (channels > MAX_CHANNELS) {
460
-        av_log(avctx, AV_LOG_ERROR, "channels > %d not supported\n",
461
-               MAX_CHANNELS);
462
-        return -1;
459
+    if (channels != avctx->channels) {
460
+        av_log(avctx, AV_LOG_ERROR, "frame header channel count mismatch\n");
461
+        return AVERROR_INVALIDDATA;
463 462
     }
464 463
 
465 464
     /* 2^result = something to do with output waiting.
... ...
@@ -634,7 +633,6 @@ static av_cold int alac_decode_init(AVCodecContext * avctx)
634 634
 {
635 635
     ALACContext *alac = avctx->priv_data;
636 636
     alac->avctx = avctx;
637
-    alac->numchannels = alac->avctx->channels;
638 637
 
639 638
     /* initialize from the extradata */
640 639
     if (alac->avctx->extradata_size != ALAC_EXTRADATA_SIZE) {
... ...
@@ -657,6 +655,21 @@ static av_cold int alac_decode_init(AVCodecContext * avctx)
657 657
              return -1;
658 658
     }
659 659
 
660
+    if (alac->numchannels < 1) {
661
+        av_log(avctx, AV_LOG_WARNING, "Invalid channel count\n");
662
+        alac->numchannels = avctx->channels;
663
+    } else {
664
+        if (alac->numchannels > MAX_CHANNELS)
665
+            alac->numchannels = avctx->channels;
666
+        else
667
+            avctx->channels = alac->numchannels;
668
+    }
669
+    if (avctx->channels > MAX_CHANNELS) {
670
+        av_log(avctx, AV_LOG_ERROR, "Unsupported channel count: %d\n",
671
+               avctx->channels);
672
+        return AVERROR_PATCHWELCOME;
673
+    }
674
+
660 675
     return 0;
661 676
 }
662 677