PR #26113 opened by fuzzyrichie URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26113 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26113.patch
The reset loop assigned the second-channel noise seed to che->ch[1] for every element and never initialized the first channel, leaving it at zero. It now selects the seed by the channel index j, giving the first channel 0x3039 and the second 0x10932 as required. This restores correct noise-fill state for SCE, LFE and CPE elements. When a fragmented extension payload finished, the accumulated byte offset was left set after the fragment buffer was released. A later continuation fragment then allocated a fresh buffer and parsed its leading bytes even though they had never been written, so decoder decisions were driven by stale/uninitialized data. Clearing the offset when the fragment buffer is released makes the next fragment start from a clean, fully initialized buffer. The EXSS descriptor parser read variable-length fields without verifying that the requested bits were within the descriptor, so malformed data could cause reads past the end of the frame. The change adds bounds checks b efore each read and ensures the descriptor size fits within the available data, returning an error instead of reading beyond the buffer. >From d76425ac29c50e38b636f89900e1a667a4302657 Mon Sep 17 00:00:00 2001 From: Richard Desmarais <[email protected]> Date: Mon, 16 Nov 2026 12:08:56 -0500 Subject: [PATCH] aacdec_usac: Fix per-channel noise seed initialization (+2 related fixes) --- libavcodec/Makefile | 2 + libavcodec/aac/aacdec_usac.c | 5 +- libavcodec/dca_exss.c | 263 ++++++++++++++++++++++++++--------- libavcodec/tests/aac_usac.c | 82 +++++++++++ libavcodec/tests/dca_exss.c | 61 ++++++++ 5 files changed, 342 insertions(+), 71 deletions(-) create mode 100644 libavcodec/tests/aac_usac.c create mode 100644 libavcodec/tests/dca_exss.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index f12ad9c8e8d..7dd362f1122 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1393,12 +1393,14 @@ TESTPROGS = avcodec \ mathops \ packet_side_data_handle \ +TESTPROGS-$(CONFIG_AAC_DECODER) += aac_usac TESTPROGS-$(CONFIG_AC3DSP) += ac3 TESTPROGS-$(CONFIG_APV_DECODER) += apv TESTPROGS-$(CONFIG_AV1_VAAPI_ENCODER) += av1_levels TESTPROGS-$(CONFIG_CABAC) += cabac TESTPROGS-$(CONFIG_CAVS_DECODER) += cavsdsp TESTPROGS-$(CONFIG_CELP_MATH) += celp_math +TESTPROGS-$(CONFIG_DCA_DECODER) += dca_exss TESTPROGS-$(CONFIG_ENCODERS) += hw_base_encode TESTPROGS-$(CONFIG_GOLOMB) += golomb TESTPROGS-$(CONFIG_IDCTDSP) += dct diff --git a/libavcodec/aac/aacdec_usac.c b/libavcodec/aac/aacdec_usac.c index e29457a1bd7..baf2a456484 100644 --- a/libavcodec/aac/aacdec_usac.c +++ b/libavcodec/aac/aacdec_usac.c @@ -536,10 +536,10 @@ int ff_aac_usac_reset_state(AACDecContext *ac, OutputConfiguration *oc) memset(ue, 0, sizeof(*ue)); - if (!ch) + if (!j) ue->noise.seed = 0x3039; else - che->ch[1].ue.noise.seed = 0x10932; + ue->noise.seed = 0x10932; } } } @@ -2065,6 +2065,7 @@ static int parse_ext_ele(AACDecContext *ac, AACUsacElemConfig *e, av_assert0(0); } av_refstruct_unref(&e->ext.pl_buf); + e->ext.pl_data_offset = 0; if (ret < 0) return ret; diff --git a/libavcodec/dca_exss.c b/libavcodec/dca_exss.c index e873088f82d..c6c2de96162 100644 --- a/libavcodec/dca_exss.c +++ b/libavcodec/dca_exss.c @@ -20,51 +20,86 @@ #include "dcadec.h" -static void parse_xll_parameters(DCAExssParser *s, DCAExssAsset *asset) +static int parse_xll_parameters(DCAExssParser *s, DCAExssAsset *asset, int descr_end) { // Size of XLL data in extension substream + if (get_bits_count(&s->gb) + s->exss_size_nbits > descr_end) + return AVERROR_INVALIDDATA; asset->xll_size = get_bits(&s->gb, s->exss_size_nbits) + 1; // XLL sync word present flag + if (get_bits_count(&s->gb) + 1 > descr_end) + return AVERROR_INVALIDDATA; if (asset->xll_sync_present = get_bits1(&s->gb)) { int xll_delay_nbits; // Peak bit rate smoothing buffer size + if (get_bits_count(&s->gb) + 4 > descr_end) + return AVERROR_INVALIDDATA; skip_bits(&s->gb, 4); // Number of bits for XLL decoding delay + if (get_bits_count(&s->gb) + 5 > descr_end) + return AVERROR_INVALIDDATA; xll_delay_nbits = get_bits(&s->gb, 5) + 1; // Initial XLL decoding delay in frames + if (get_bits_count(&s->gb) + xll_delay_nbits > descr_end) + return AVERROR_INVALIDDATA; asset->xll_delay_nframes = get_bits_long(&s->gb, xll_delay_nbits); // Number of bytes offset to XLL sync + if (get_bits_count(&s->gb) + s->exss_size_nbits > descr_end) + return AVERROR_INVALIDDATA; asset->xll_sync_offset = get_bits(&s->gb, s->exss_size_nbits); } else { asset->xll_delay_nframes = 0; asset->xll_sync_offset = 0; } + return 0; } -static void parse_lbr_parameters(DCAExssParser *s, DCAExssAsset *asset) +static int parse_lbr_parameters(DCAExssParser *s, DCAExssAsset *asset, int descr_end) { // Size of LBR component in extension substream + if (get_bits_count(&s->gb) + 14 > descr_end) + return AVERROR_INVALIDDATA; asset->lbr_size = get_bits(&s->gb, 14) + 1; // LBR sync word present flag - if (get_bits1(&s->gb)) + if (get_bits_count(&s->gb) + 1 > descr_end) + return AVERROR_INVALIDDATA; + if (get_bits1(&s->gb)) { // LBR sync distance + if (get_bits_count(&s->gb) + 2 > descr_end) + return AVERROR_INVALIDDATA; skip_bits(&s->gb, 2); + } + return 0; } static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset) { int i, j, drc_present, descr_size, descr_pos = get_bits_count(&s->gb); + int descr_end, ret; // Size of audio asset descriptor in bytes + if (get_bits_left(&s->gb) < 9) + return AVERROR_INVALIDDATA; descr_size = get_bits(&s->gb, 9) + 1; + if (descr_size < 2) + return AVERROR_INVALIDDATA; + if (descr_size * 8 > get_bits_left(&s->gb) + 9) + return AVERROR_INVALIDDATA; + descr_end = descr_pos + descr_size * 8; + +#define CHECK_DESCR_BITS(n) do { \ + if (get_bits_count(&s->gb) + (n) > descr_end) \ + return AVERROR_INVALIDDATA; \ +} while (0) // Audio asset identifier + CHECK_DESCR_BITS(3); asset->asset_index = get_bits(&s->gb, 3); // @@ -73,59 +108,85 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset) if (s->static_fields_present) { // Asset type descriptor presence - if (get_bits1(&s->gb)) + CHECK_DESCR_BITS(1); + if (get_bits1(&s->gb)) { // Asset type descriptor + CHECK_DESCR_BITS(4); skip_bits(&s->gb, 4); + } // Language descriptor presence - if (get_bits1(&s->gb)) + CHECK_DESCR_BITS(1); + if (get_bits1(&s->gb)) { // Language descriptor + CHECK_DESCR_BITS(24); skip_bits(&s->gb, 24); + } // Additional textual information presence + CHECK_DESCR_BITS(1); if (get_bits1(&s->gb)) { // Byte size of additional text info - int text_size = get_bits(&s->gb, 10) + 1; + int text_size; + CHECK_DESCR_BITS(10); + text_size = get_bits(&s->gb, 10) + 1; // Sanity check available size - if (get_bits_left(&s->gb) < text_size * 8) - return AVERROR_INVALIDDATA; + CHECK_DESCR_BITS(text_size * 8); // Additional textual information string skip_bits_long(&s->gb, text_size * 8); } // PCM bit resolution + CHECK_DESCR_BITS(5); asset->pcm_bit_res = get_bits(&s->gb, 5) + 1; // Maximum sample rate + CHECK_DESCR_BITS(4); asset->max_sample_rate = ff_dca_sampling_freqs[get_bits(&s->gb, 4)]; // Total number of channels + CHECK_DESCR_BITS(8); asset->nchannels_total = get_bits(&s->gb, 8) + 1; // One to one map channel to speakers + CHECK_DESCR_BITS(1); if (asset->one_to_one_map_ch_to_spkr = get_bits1(&s->gb)) { int spkr_mask_nbits = 0; int spkr_remap_nsets; int nspeakers[8]; // Embedded stereo flag - asset->embedded_stereo = asset->nchannels_total > 2 && get_bits1(&s->gb); + if (asset->nchannels_total > 2) { + CHECK_DESCR_BITS(1); + asset->embedded_stereo = get_bits1(&s->gb); + } else { + asset->embedded_stereo = 0; + } // Embedded 6 channels flag - asset->embedded_6ch = asset->nchannels_total > 6 && get_bits1(&s->gb); + if (asset->nchannels_total > 6) { + CHECK_DESCR_BITS(1); + asset->embedded_6ch = get_bits1(&s->gb); + } else { + asset->embedded_6ch = 0; + } // Speaker mask enabled flag + CHECK_DESCR_BITS(1); if (asset->spkr_mask_enabled = get_bits1(&s->gb)) { // Number of bits for speaker activity mask + CHECK_DESCR_BITS(2); spkr_mask_nbits = (get_bits(&s->gb, 2) + 1) << 2; // Loudspeaker activity mask + CHECK_DESCR_BITS(spkr_mask_nbits); asset->spkr_mask = get_bits(&s->gb, spkr_mask_nbits); } // Number of speaker remapping sets + CHECK_DESCR_BITS(3); if ((spkr_remap_nsets = get_bits(&s->gb, 3)) && !spkr_mask_nbits) { if (s->avctx) av_log(s->avctx, AV_LOG_ERROR, "Speaker mask disabled yet there are remapping sets\n"); @@ -133,18 +194,25 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset) } // Standard loudspeaker layout mask - for (i = 0; i < spkr_remap_nsets; i++) + for (i = 0; i < spkr_remap_nsets; i++) { + CHECK_DESCR_BITS(spkr_mask_nbits); nspeakers[i] = ff_dca_count_chs_for_mask(get_bits(&s->gb, spkr_mask_nbits)); + } for (i = 0; i < spkr_remap_nsets; i++) { // Number of channels to be decoded for speaker remapping - int nch_for_remaps = get_bits(&s->gb, 5) + 1; + int nch_for_remaps; + CHECK_DESCR_BITS(5); + nch_for_remaps = get_bits(&s->gb, 5) + 1; for (j = 0; j < nspeakers[i]; j++) { // Decoded channels to output speaker mapping mask - int remap_ch_mask = get_bits_long(&s->gb, nch_for_remaps); + int remap_ch_mask; + CHECK_DESCR_BITS(nch_for_remaps); + remap_ch_mask = get_bits_long(&s->gb, nch_for_remaps); // Loudspeaker remapping codes + CHECK_DESCR_BITS(av_popcount(remap_ch_mask) * 5); skip_bits_long(&s->gb, av_popcount(remap_ch_mask) * 5); } } @@ -155,6 +223,7 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset) asset->spkr_mask = 0; // Representation type + CHECK_DESCR_BITS(3); asset->representation_type = get_bits(&s->gb, 3); } } @@ -164,65 +233,90 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset) // // Dynamic range coefficient presence flag + CHECK_DESCR_BITS(1); drc_present = get_bits1(&s->gb); // Code for dynamic range coefficient - if (drc_present) + if (drc_present) { + CHECK_DESCR_BITS(8); skip_bits(&s->gb, 8); + } // Dialog normalization presence flag - if (get_bits1(&s->gb)) + CHECK_DESCR_BITS(1); + if (get_bits1(&s->gb)) { // Dialog normalization code + CHECK_DESCR_BITS(5); skip_bits(&s->gb, 5); + } // DRC for stereo downmix - if (drc_present && asset->embedded_stereo) + if (drc_present && asset->embedded_stereo) { + CHECK_DESCR_BITS(8); skip_bits(&s->gb, 8); + } // Mixing metadata presence flag - if (s->mix_metadata_enabled && get_bits1(&s->gb)) { - int nchannels_dmix; + if (s->mix_metadata_enabled) { + CHECK_DESCR_BITS(1); + if (get_bits1(&s->gb)) { + int nchannels_dmix; - // External mixing flag - skip_bits1(&s->gb); + // External mixing flag + CHECK_DESCR_BITS(1); + skip_bits1(&s->gb); - // Post mixing / replacement gain adjustment - skip_bits(&s->gb, 6); + // Post mixing / replacement gain adjustment + CHECK_DESCR_BITS(6); + skip_bits(&s->gb, 6); - // DRC prior to mixing - if (get_bits(&s->gb, 2) == 3) - // Custom code for mixing DRC - skip_bits(&s->gb, 8); - else - // Limit for mixing DRC - skip_bits(&s->gb, 3); - - // Scaling type for channels of main audio - // Scaling parameters of main audio - if (get_bits1(&s->gb)) - for (i = 0; i < s->nmixoutconfigs; i++) - skip_bits_long(&s->gb, 6 * s->nmixoutchs[i]); - else - skip_bits_long(&s->gb, 6 * s->nmixoutconfigs); - - nchannels_dmix = asset->nchannels_total; - if (asset->embedded_6ch) - nchannels_dmix += 6; - if (asset->embedded_stereo) - nchannels_dmix += 2; - - for (i = 0; i < s->nmixoutconfigs; i++) { - if (!s->nmixoutchs[i]) { - if (s->avctx) - av_log(s->avctx, AV_LOG_ERROR, "Invalid speaker layout mask for mixing configuration\n"); - return AVERROR_INVALIDDATA; + // DRC prior to mixing + CHECK_DESCR_BITS(2); + if (get_bits(&s->gb, 2) == 3) { + // Custom code for mixing DRC + CHECK_DESCR_BITS(8); + skip_bits(&s->gb, 8); + } else { + // Limit for mixing DRC + CHECK_DESCR_BITS(3); + skip_bits(&s->gb, 3); } - for (j = 0; j < nchannels_dmix; j++) { - // Mix output mask - int mix_map_mask = get_bits(&s->gb, s->nmixoutchs[i]); - // Mixing coefficients - skip_bits_long(&s->gb, av_popcount(mix_map_mask) * 6); + // Scaling type for channels of main audio + // Scaling parameters of main audio + CHECK_DESCR_BITS(1); + if (get_bits1(&s->gb)) { + for (i = 0; i < s->nmixoutconfigs; i++) { + CHECK_DESCR_BITS(6 * s->nmixoutchs[i]); + skip_bits_long(&s->gb, 6 * s->nmixoutchs[i]); + } + } else { + CHECK_DESCR_BITS(6 * s->nmixoutconfigs); + skip_bits_long(&s->gb, 6 * s->nmixoutconfigs); + } + + nchannels_dmix = asset->nchannels_total; + if (asset->embedded_6ch) + nchannels_dmix += 6; + if (asset->embedded_stereo) + nchannels_dmix += 2; + + for (i = 0; i < s->nmixoutconfigs; i++) { + if (!s->nmixoutchs[i]) { + if (s->avctx) + av_log(s->avctx, AV_LOG_ERROR, "Invalid speaker layout mask for mixing configuration\n"); + return AVERROR_INVALIDDATA; + } + for (j = 0; j < nchannels_dmix; j++) { + // Mix output mask + int mix_map_mask; + CHECK_DESCR_BITS(s->nmixoutchs[i]); + mix_map_mask = get_bits(&s->gb, s->nmixoutchs[i]); + + // Mixing coefficients + CHECK_DESCR_BITS(av_popcount(mix_map_mask) * 6); + skip_bits_long(&s->gb, av_popcount(mix_map_mask) * 6); + } } } } @@ -232,76 +326,105 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset) // // Coding mode for the asset + CHECK_DESCR_BITS(2); asset->coding_mode = get_bits(&s->gb, 2); // Coding components used in asset switch (asset->coding_mode) { case 0: // Coding mode that may contain multiple coding components + CHECK_DESCR_BITS(12); asset->extension_mask = get_bits(&s->gb, 12); if (asset->extension_mask & DCA_EXSS_CORE) { // Size of core component in extension substream + CHECK_DESCR_BITS(14); asset->core_size = get_bits(&s->gb, 14) + 1; // Core sync word present flag - if (get_bits1(&s->gb)) + CHECK_DESCR_BITS(1); + if (get_bits1(&s->gb)) { // Core sync distance + CHECK_DESCR_BITS(2); skip_bits(&s->gb, 2); + } } - if (asset->extension_mask & DCA_EXSS_XBR) + if (asset->extension_mask & DCA_EXSS_XBR) { // Size of XBR extension in extension substream + CHECK_DESCR_BITS(14); asset->xbr_size = get_bits(&s->gb, 14) + 1; + } - if (asset->extension_mask & DCA_EXSS_XXCH) + if (asset->extension_mask & DCA_EXSS_XXCH) { // Size of XXCH extension in extension substream + CHECK_DESCR_BITS(14); asset->xxch_size = get_bits(&s->gb, 14) + 1; + } - if (asset->extension_mask & DCA_EXSS_X96) + if (asset->extension_mask & DCA_EXSS_X96) { // Size of X96 extension in extension substream + CHECK_DESCR_BITS(12); asset->x96_size = get_bits(&s->gb, 12) + 1; + } - if (asset->extension_mask & DCA_EXSS_LBR) - parse_lbr_parameters(s, asset); + if (asset->extension_mask & DCA_EXSS_LBR) { + if ((ret = parse_lbr_parameters(s, asset, descr_end)) < 0) + return ret; + } - if (asset->extension_mask & DCA_EXSS_XLL) - parse_xll_parameters(s, asset); + if (asset->extension_mask & DCA_EXSS_XLL) { + if ((ret = parse_xll_parameters(s, asset, descr_end)) < 0) + return ret; + } - if (asset->extension_mask & DCA_EXSS_RSV1) + if (asset->extension_mask & DCA_EXSS_RSV1) { + CHECK_DESCR_BITS(16); skip_bits(&s->gb, 16); + } - if (asset->extension_mask & DCA_EXSS_RSV2) + if (asset->extension_mask & DCA_EXSS_RSV2) { + CHECK_DESCR_BITS(16); skip_bits(&s->gb, 16); + } break; case 1: // Loss-less coding mode without CBR component asset->extension_mask = DCA_EXSS_XLL; - parse_xll_parameters(s, asset); + if ((ret = parse_xll_parameters(s, asset, descr_end)) < 0) + return ret; break; case 2: // Low bit rate mode asset->extension_mask = DCA_EXSS_LBR; - parse_lbr_parameters(s, asset); + if ((ret = parse_lbr_parameters(s, asset, descr_end)) < 0) + return ret; break; case 3: // Auxiliary coding mode asset->extension_mask = 0; // Size of auxiliary coded data + CHECK_DESCR_BITS(14); skip_bits(&s->gb, 14); // Auxiliary codec identification + CHECK_DESCR_BITS(8); skip_bits(&s->gb, 8); // Aux sync word present flag - if (get_bits1(&s->gb)) + CHECK_DESCR_BITS(1); + if (get_bits1(&s->gb)) { // Aux sync distance + CHECK_DESCR_BITS(3); skip_bits(&s->gb, 3); + } break; } - if (asset->extension_mask & DCA_EXSS_XLL) + if (asset->extension_mask & DCA_EXSS_XLL) { // DTS-HD stream ID + CHECK_DESCR_BITS(3); asset->hd_stream_id = get_bits(&s->gb, 3); + } // One to one mixing flag // Per channel main audio scaling flag @@ -310,12 +433,14 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset) // Revision 2 DRC metadata // Reserved // Zero pad - if (ff_dca_seek_bits(&s->gb, descr_pos + descr_size * 8)) { + if (ff_dca_seek_bits(&s->gb, descr_end)) { if (s->avctx) av_log(s->avctx, AV_LOG_ERROR, "Read past end of EXSS asset descriptor\n"); return AVERROR_INVALIDDATA; } +#undef CHECK_DESCR_BITS + return 0; } diff --git a/libavcodec/tests/aac_usac.c b/libavcodec/tests/aac_usac.c new file mode 100644 index 00000000000..815335d8f01 --- /dev/null +++ b/libavcodec/tests/aac_usac.c @@ -0,0 +1,82 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <stdio.h> +#include <string.h> + +#include "libavcodec/aac/aacdec_usac.c" + +static int append_fragment(AACDecContext *ac, AACUsacElemConfig *e, + int start, int end, const uint8_t *data, int len) +{ + uint8_t buf[64] = { 0 }; + PutBitContext pb; + GetBitContext gb; + int size; + + init_put_bits(&pb, buf, sizeof(buf)); + put_bits(&pb, 1, start); + put_bits(&pb, 1, end); + put_bits(&pb, 8, len); + for (int i = 0; i < len; i++) + put_bits(&pb, 8, data[i]); + flush_put_bits(&pb); + + size = (put_bits_count(&pb) + 7) / 8; + init_get_bits8(&gb, buf, size); + + return parse_ext_ele(ac, &gb, e); +} + +int main(void) +{ + AVCodecContext *avctx = avcodec_alloc_context3(NULL); + AACDecContext ac; + AACUsacElemConfig e; + uint8_t data[2] = { 0xaa, 0xbb }; + + if (!avctx) + return 1; + + memset(&ac, 0, sizeof(ac)); + memset(&e, 0, sizeof(e)); + ac.avctx = avctx; + + e.ext.type = 0; + e.ext.payload_length_bits = 8; + + append_fragment(&ac, &e, 1, 0, data, 1); + if (e.ext.pl_data_offset != 1) { + fprintf(stderr, "unexpected extension payload offset after first fragment: %d\n", + e.ext.pl_data_offset); + avcodec_free_context(&avctx); + return 1; + } + + append_fragment(&ac, &e, 0, 1, data + 1, 1); + + if (e.ext.pl_data_offset != 0) { + fprintf(stderr, "extension payload offset not reset after completed fragment: %d\n", + e.ext.pl_data_offset); + avcodec_free_context(&avctx); + return 1; + } + + avcodec_free_context(&avctx); + return 0; +} diff --git a/libavcodec/tests/dca_exss.c b/libavcodec/tests/dca_exss.c new file mode 100644 index 00000000000..694a50b693e --- /dev/null +++ b/libavcodec/tests/dca_exss.c @@ -0,0 +1,61 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <stdint.h> + +#include "libavutil/error.h" +#include "libavutil/log.h" +#include "libavutil/mem.h" +#include "libavcodec/dcadec.h" +#include "libavcodec/put_bits.h" + +int main(void) +{ + uint8_t *buf; + PutBitContext pb; + DCAExssParser s = { 0 }; + int ret; + + /* The buffer ends just before the asset descriptor size field. */ + buf = av_mallocz(11); + if (!buf) + return 1; + + init_put_bits(&pb, buf, 11); + put_bits32(&pb, 0); // sync word + put_bits(&pb, 8, 0); // user defined bits + put_bits(&pb, 2, 0); // extension substream index + put_bits(&pb, 1, 0); // short header + put_bits(&pb, 8, 0); // header size = 1 byte + put_bits(&pb, 16, 10); // extension substream size = 11 bytes + put_bits(&pb, 1, 0); // no static fields + put_bits(&pb, 16, 0); // asset size = 1 byte + flush_put_bits(&pb); + + ret = ff_dca_exss_parse(&s, buf, 11); + av_free(buf); + + if (ret != AVERROR_INVALIDDATA) { + av_log(NULL, AV_LOG_ERROR, + "Expected AVERROR_INVALIDDATA for truncated asset descriptor, got %d\n", + ret); + return 1; + } + + return 0; +} -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
