Commit 18a851ac authored by Andreas Rheinhardt via ffmpeg-devel's avatar Andreas Rheinhardt via ffmpeg-devel Committed by Michael Niedermayer

avformat/matroskadec: Improve length check

The earlier code had three flaws:

1. The case of an unknown-sized element inside a finite-sized element
(which is against the specifications) was not caught.

2. The error message wasn't helpful: It compared the length of the child
with the offset of the end of the parent and claimed that the first
exceeds the latter, although that is not necessarily true.

3. Unknown-sized elements that are not parsed can't be skipped. Given
that according to the Matroska specifications only the segment and the
clusters can be of unknown-size, this is handled by not allowing any
other units to have infinite size whereas the earlier code would seek
back by 1 byte upon encountering an infinite-size element that ought
to be skipped.
Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@googlemail.com>
Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 8e3b01e2
...@@ -1203,11 +1203,29 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska, ...@@ -1203,11 +1203,29 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska,
MatroskaLevel *level = &matroska->levels[matroska->num_levels - 1]; MatroskaLevel *level = &matroska->levels[matroska->num_levels - 1];
AVIOContext *pb = matroska->ctx->pb; AVIOContext *pb = matroska->ctx->pb;
int64_t pos = avio_tell(pb); int64_t pos = avio_tell(pb);
if (level->length != EBML_UNKNOWN_LENGTH &&
(pos + length) > (level->start + level->length)) { if (length != EBML_UNKNOWN_LENGTH &&
level->length != EBML_UNKNOWN_LENGTH) {
uint64_t elem_end = pos + length,
level_end = level->start + level->length;
if (level_end < elem_end) {
av_log(matroska->ctx, AV_LOG_ERROR,
"Element at 0x%"PRIx64" ending at 0x%"PRIx64" exceeds "
"containing master element ending at 0x%"PRIx64"\n",
pos, elem_end, level_end);
return AVERROR_INVALIDDATA;
}
} else if (level->length != EBML_UNKNOWN_LENGTH) {
av_log(matroska->ctx, AV_LOG_ERROR, "Unknown-sized element "
"at 0x%"PRIx64" inside parent with finite size\n", pos);
return AVERROR_INVALIDDATA;
} else if (length == EBML_UNKNOWN_LENGTH && id != MATROSKA_ID_CLUSTER) {
// According to the specifications only clusters and segments
// are allowed to be unknown-sized.
av_log(matroska->ctx, AV_LOG_ERROR, av_log(matroska->ctx, AV_LOG_ERROR,
"Invalid length 0x%"PRIx64" > 0x%"PRIx64" in parent\n", "Found unknown-sized element other than a cluster at "
length, level->start + level->length); "0x%"PRIx64". Dropping the invalid element.\n", pos);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment