alsdec: ensure channel reordering is reversible
authorAndreas Cadhalpun <andreas.cadhalpun@googlemail.com>
Sat, 18 Apr 2015 16:31:36 +0000 (18:31 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sat, 18 Apr 2015 17:26:17 +0000 (19:26 +0200)
If the same idx is used for more than one i, at least one entry in
sconf->chan_pos remains uninitialized.

This can cause segmentation faults.

Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavcodec/alsdec.c

index 65aa7d2..f85f1e8 100644 (file)
@@ -357,11 +357,15 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
 
         ctx->cs_switch = 1;
 
+        for (i = 0; i < avctx->channels; i++) {
+            sconf->chan_pos[i] = -1;
+        }
+
         for (i = 0; i < avctx->channels; i++) {
             int idx;
 
             idx = get_bits(&gb, chan_pos_bits);
-            if (idx >= avctx->channels) {
+            if (idx >= avctx->channels || sconf->chan_pos[idx] != -1) {
                 av_log(avctx, AV_LOG_WARNING, "Invalid channel reordering.\n");
                 ctx->cs_switch = 0;
                 break;