# HG changeset patch # User ramiro # Date 1240351950 0 # Node ID 19a70bcc2220f92b3730a8e9bfa66282bb2f0cc4 # Parent dbb16aa52d4314fbfdca0b5889702dc9165cd6c4 mlpdec: Validate max_channel and max_matrix_channel. diff -r dbb16aa52d43 -r 19a70bcc2220 mlp.h --- a/mlp.h Tue Apr 21 21:57:23 2009 +0000 +++ b/mlp.h Tue Apr 21 22:12:30 2009 +0000 @@ -26,6 +26,9 @@ #include "avcodec.h" +/** Last possible matrix channel for each codec */ +#define MAX_MATRIX_CHANNEL_MLP 5 +#define MAX_MATRIX_CHANNEL_TRUEHD 7 /** Maximum number of channels that can be decoded. */ #define MAX_CHANNELS 16 diff -r dbb16aa52d43 -r 19a70bcc2220 mlpdec.c --- a/mlpdec.c Tue Apr 21 21:57:23 2009 +0000 +++ b/mlpdec.c Tue Apr 21 22:12:30 2009 +0000 @@ -335,6 +335,9 @@ uint8_t checksum; uint8_t lossless_check; int start_count = get_bits_count(gbp); + const int max_matrix_channel = m->avctx->codec_id == CODEC_ID_MLP + ? MAX_MATRIX_CHANNEL_MLP + : MAX_MATRIX_CHANNEL_TRUEHD; sync_word = get_bits(gbp, 13); s->noise_type = get_bits1(gbp); @@ -352,6 +355,19 @@ s->max_channel = get_bits(gbp, 4); s->max_matrix_channel = get_bits(gbp, 4); + if (s->max_matrix_channel > max_matrix_channel) { + av_log(m->avctx, AV_LOG_ERROR, + "Max matrix channel cannot be greater than %d.\n", + max_matrix_channel); + return -1; + } + + if (s->max_channel != s->max_matrix_channel) { + av_log(m->avctx, AV_LOG_ERROR, + "Max channel must be equal max matrix channel.\n"); + return -1; + } + if (s->min_channel > s->max_channel) { av_log(m->avctx, AV_LOG_ERROR, "Substream min channel cannot be greater than max channel.\n");