mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-10-18 20:43:26 +00:00
avcodec/hcadec: add a flush callback
Fixes unexpected behavior during seeking and with fuzzed samples. Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
19baf4e009
commit
9078dc0c52
@ -65,6 +65,7 @@ typedef struct HCAContext {
|
|||||||
uint8_t stereo_band_count;
|
uint8_t stereo_band_count;
|
||||||
uint8_t bands_per_hfr_group;
|
uint8_t bands_per_hfr_group;
|
||||||
|
|
||||||
|
// Set during init() and freed on close(). Untouched on flush()
|
||||||
av_tx_fn tx_fn;
|
av_tx_fn tx_fn;
|
||||||
AVTXContext *tx_ctx;
|
AVTXContext *tx_ctx;
|
||||||
AVFloatDSPContext *fdsp;
|
AVFloatDSPContext *fdsp;
|
||||||
@ -196,6 +197,13 @@ static inline unsigned ceil2(unsigned a, unsigned b)
|
|||||||
return (b > 0) ? (a / b + ((a % b) ? 1 : 0)) : 0;
|
return (b > 0) ? (a / b + ((a % b) ? 1 : 0)) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static av_cold void decode_flush(AVCodecContext *avctx)
|
||||||
|
{
|
||||||
|
HCAContext *c = avctx->priv_data;
|
||||||
|
|
||||||
|
memset(c, 0, offsetof(HCAContext, tx_fn));
|
||||||
|
}
|
||||||
|
|
||||||
static int init_hca(AVCodecContext *avctx, const uint8_t *extradata,
|
static int init_hca(AVCodecContext *avctx, const uint8_t *extradata,
|
||||||
const int extradata_size)
|
const int extradata_size)
|
||||||
{
|
{
|
||||||
@ -205,6 +213,8 @@ static int init_hca(AVCodecContext *avctx, const uint8_t *extradata,
|
|||||||
unsigned b, chunk;
|
unsigned b, chunk;
|
||||||
int version, ret;
|
int version, ret;
|
||||||
|
|
||||||
|
decode_flush(avctx);
|
||||||
|
|
||||||
if (extradata_size < 36)
|
if (extradata_size < 36)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
|
|
||||||
@ -340,6 +350,9 @@ static int init_hca(AVCodecContext *avctx, const uint8_t *extradata,
|
|||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Done last to signal init() finished
|
||||||
|
c->crc_table = av_crc_get_table(AV_CRC_16_ANSI);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,7 +363,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
|
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
|
||||||
c->crc_table = av_crc_get_table(AV_CRC_16_ANSI);
|
|
||||||
|
|
||||||
if (avctx->ch_layout.nb_channels <= 0 || avctx->ch_layout.nb_channels > FF_ARRAY_ELEMS(c->ch))
|
if (avctx->ch_layout.nb_channels <= 0 || avctx->ch_layout.nb_channels > FF_ARRAY_ELEMS(c->ch))
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
@ -534,6 +546,9 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!c->crc_table)
|
||||||
|
return AVERROR_INVALIDDATA;
|
||||||
|
|
||||||
if (c->key || c->subkey) {
|
if (c->key || c->subkey) {
|
||||||
uint8_t *data, *cipher = c->cipher;
|
uint8_t *data, *cipher = c->cipher;
|
||||||
|
|
||||||
@ -602,6 +617,7 @@ const FFCodec ff_hca_decoder = {
|
|||||||
.priv_data_size = sizeof(HCAContext),
|
.priv_data_size = sizeof(HCAContext),
|
||||||
.init = decode_init,
|
.init = decode_init,
|
||||||
FF_CODEC_DECODE_CB(decode_frame),
|
FF_CODEC_DECODE_CB(decode_frame),
|
||||||
|
.flush = decode_flush,
|
||||||
.close = decode_close,
|
.close = decode_close,
|
||||||
.p.capabilities = AV_CODEC_CAP_DR1,
|
.p.capabilities = AV_CODEC_CAP_DR1,
|
||||||
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
|
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
|
||||||
|
Loading…
Reference in New Issue
Block a user