The only offical profile i could find (ALS simple profile) has a max of 15 while the bitstream allows 1023 which is very slow. We do have a fate sample with 1023 Fixes: Timeout Fixes: 429645375/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ALS_fuzzer-5377900448907264
Unified · Split
| @@ -38,6 +38,7 @@ · 37 unmodified lines | ||
| 38 | 38 | #include "internal.h" |
| 39 | 39 | #include "mlz.h" |
| 40 | 40 | #include "libavutil/mem.h" |
| 41 | +#include "libavutil/opt.h" | |
| 41 | 42 | #include "libavutil/samplefmt.h" |
| 42 | 43 | #include "libavutil/crc.h" |
| 43 | 44 | #include "libavutil/softfloat_ieee754.h" |
| @@ -194,6 +195,7 @@ typedef struct ALSChannelData { · 150 unmodified lines | ||
| 194 | 195 | |
| 195 | 196 | |
| 196 | 197 | typedef struct ALSDecContext { |
| 198 | + AVClass *av_class; | |
| 197 | 199 | AVCodecContext *avctx; |
| 198 | 200 | ALSSpecificConfig sconf; |
| 199 | 201 | GetBitContext gb; |
| @@ -239,6 +241,7 @@ typedef struct ALSDecContext { · 39 unmodified lines | ||
| 239 | 241 | unsigned char *larray; ///< buffer to store the output of masked lz decompression |
| 240 | 242 | int *nbits; ///< contains the number of bits to read for masked lz decompression for all samples |
| 241 | 243 | int highest_decoded_channel; |
| 244 | + int user_max_order; ///< user specified maximum prediction order | |
| 242 | 245 | } ALSDecContext; |
| 243 | 246 | |
| 244 | 247 | |
| @@ -352,6 +355,11 @@ static av_cold int read_specific_config(ALSDecContext *ctx) · 107 unmodified lines | ||
| 352 | 355 | skip_bits(&gb, 5); // skip 5 reserved bits |
| 353 | 356 | skip_bits1(&gb); // skip aux_data_enabled |
| 354 | 357 | |
| 358 | + if (sconf->max_order > ctx->user_max_order) { | |
| 359 | + av_log(avctx, AV_LOG_ERROR, "order %d exceeds specified max %d\n", sconf->max_order, ctx->user_max_order); | |
| 360 | + return AVERROR_INVALIDDATA; | |
| 361 | + } | |
| 362 | + | |
| 355 | 363 | |
| 356 | 364 | // check for ALSSpecificConfig struct |
| 357 | 365 | if (als_id != MKBETAG('A','L','S','\0')) |
| @@ -2183,6 +2191,17 @@ static av_cold void flush(AVCodecContext *avctx) · 1825 unmodified lines | ||
| 2183 | 2191 | ctx->frame_id = 0; |
| 2184 | 2192 | } |
| 2185 | 2193 | |
| 2194 | +static const AVOption options[] = { | |
| 2195 | + { "max_order", "Sets the maximum order (ALS simple profile allows max 15)", offsetof(ALSDecContext, user_max_order), AV_OPT_TYPE_INT, { .i64 = 1023 }, 0, 1023, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM }, | |
| 2196 | + { NULL } | |
| 2197 | +}; | |
| 2198 | + | |
| 2199 | +static const AVClass als_class = { | |
| 2200 | + .class_name = "als", | |
| 2201 | + .item_name = av_default_item_name, | |
| 2202 | + .option = options, | |
| 2203 | + .version = LIBAVUTIL_VERSION_INT, | |
| 2204 | +}; | |
| 2186 | 2205 | |
| 2187 | 2206 | const FFCodec ff_als_decoder = { |
| 2188 | 2207 | .p.name = "als", |
| @@ -2193,6 +2212,7 @@ const FFCodec ff_als_decoder = { · 4 unmodified lines | ||
| 2193 | 2212 | .init = decode_init, |
| 2194 | 2213 | .close = decode_end, |
| 2195 | 2214 | FF_CODEC_DECODE_CB(decode_frame), |
| 2215 | + .p.priv_class = &als_class, | |
| 2196 | 2216 | .flush = flush, |
| 2197 | 2217 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF, |
| 2198 | 2218 | .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, |