1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-07-11 14:30:22 +02:00

avformat/iamf_parse: add checks to parameter definition durations

Section 3.6.1 of the IAMF spec states "When constant_subblock_duration is equal to 0, the summation of all
subblock_duration in this parameter block SHALL be equal to duration.".

Signed-off-by: James Almer <jamrial@gmail.com>
(cherry picked from commit d38fc25519)
This commit is contained in:
James Almer
2024-12-11 23:27:00 -03:00
parent 3c3d252449
commit 5a8055a58a
2 changed files with 25 additions and 4 deletions

View File

@ -498,6 +498,7 @@ static int param_parse(void *s, IAMFContext *c, AVIOContext *pb,
AVIAMFParamDefinition *param;
unsigned int parameter_id, parameter_rate, mode;
unsigned int duration = 0, constant_subblock_duration = 0, nb_subblocks = 0;
unsigned int total_duration = 0;
size_t param_size;
parameter_id = ffio_read_leb(pb);
@ -518,8 +519,10 @@ static int param_parse(void *s, IAMFContext *c, AVIOContext *pb,
constant_subblock_duration = ffio_read_leb(pb);
if (constant_subblock_duration == 0)
nb_subblocks = ffio_read_leb(pb);
else
else {
nb_subblocks = duration / constant_subblock_duration;
total_duration = duration;
}
}
param = av_iamf_param_definition_alloc(type, nb_subblocks, &param_size);
@ -530,8 +533,10 @@ static int param_parse(void *s, IAMFContext *c, AVIOContext *pb,
void *subblock = av_iamf_param_definition_get_subblock(param, i);
unsigned int subblock_duration = constant_subblock_duration;
if (constant_subblock_duration == 0)
if (constant_subblock_duration == 0) {
subblock_duration = ffio_read_leb(pb);
total_duration += subblock_duration;
}
switch (type) {
case AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN: {
@ -559,6 +564,11 @@ static int param_parse(void *s, IAMFContext *c, AVIOContext *pb,
}
}
if (!mode && !constant_subblock_duration && total_duration != duration) {
av_log(s, AV_LOG_ERROR, "Invalid subblock durations in parameter_id %u\n", parameter_id);
return AVERROR_INVALIDDATA;
}
param->parameter_id = parameter_id;
param->parameter_rate = parameter_rate;
param->duration = duration;

View File

@ -108,6 +108,7 @@ static int parameter_block_obu(AVFormatContext *s, IAMFDemuxContext *c,
AVIOContext *pb;
uint8_t *buf;
unsigned int duration, constant_subblock_duration;
unsigned int total_duration = 0;
unsigned int nb_subblocks;
unsigned int parameter_id;
size_t out_param_size;
@ -146,8 +147,10 @@ static int parameter_block_obu(AVFormatContext *s, IAMFDemuxContext *c,
constant_subblock_duration = ffio_read_leb(pb);
if (constant_subblock_duration == 0)
nb_subblocks = ffio_read_leb(pb);
else
else {
nb_subblocks = duration / constant_subblock_duration;
total_duration = duration;
}
} else {
duration = param->duration;
constant_subblock_duration = param->constant_subblock_duration;
@ -171,8 +174,10 @@ static int parameter_block_obu(AVFormatContext *s, IAMFDemuxContext *c,
void *subblock = av_iamf_param_definition_get_subblock(out_param, i);
unsigned int subblock_duration = constant_subblock_duration;
if (!param_definition->mode && !constant_subblock_duration)
if (!param_definition->mode && !constant_subblock_duration) {
subblock_duration = ffio_read_leb(pb);
total_duration += subblock_duration;
}
switch (param->type) {
case AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN: {
@ -234,6 +239,12 @@ static int parameter_block_obu(AVFormatContext *s, IAMFDemuxContext *c,
av_log(s, level, "Underread in parameter_block_obu. %d bytes left at the end\n", len);
}
if (!param_definition->mode && !constant_subblock_duration && total_duration != duration) {
av_log(s, AV_LOG_ERROR, "Invalid duration in parameter block\n");
ret = AVERROR_INVALIDDATA;
goto fail;
}
switch (param->type) {
case AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN:
av_free(c->mix);