typedef struct ArithCoder {
unsigned int a;
unsigned int c;
- int overread;
} ArithCoder;
typedef struct Table {
return AVERROR_PATCHWELCOME;
}
+ // the sample rate is only allowed to be 64,128,256 * 44100 by ISO/IEC 14496-3:2005(E)
+ // We are a bit more tolerant here, but this check is needed to bound the size and duration
+ if (avctx->sample_rate > 512 * 44100)
+ return AVERROR_INVALIDDATA;
+
+
if (DST_SAMPLES_PER_FRAME(avctx->sample_rate) & 7) {
return AVERROR_PATCHWELCOME;
}
{
ac->a = 4095;
ac->c = get_bits(gb, 12);
- ac->overread = 0;
}
static av_always_inline void ac_get(ArithCoder *ac, GetBitContext *gb, int p, int *e)
if (ac->a < 2048) {
int n = 11 - av_log2(ac->a);
ac->a <<= n;
- if (get_bits_left(gb) < n)
- ac->overread ++;
ac->c = (ac->c << n) | get_bits(gb, n);
}
}
prob = 128;
}
- if (ac->overread > 16)
- return AVERROR_INVALIDDATA;
-
ac_get(ac, gb, prob, &residual);
v = ((predict >> 15) ^ residual) & 1;
dsd[((i >> 3) * channels + ch) << 2] |= v << (7 - (i & 0x7 ));