avformat/matroskadec: Improve error/EOF checks III

Up until now, when an element was skipped, it was relied upon
ffio_limit to make sure that there is enough data available to skip.
ffio_limit itself relies upon the availability of the file's size. As
this needn't be available, the check has been refined: First one byte
less than intended is skipped, then another byte is read, followed by a
check of the error flags.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
pull/315/head
Andreas Rheinhardt 6 years ago committed by James Almer
parent a569a7b3bb
commit ff5ea59f7b
  1. 24
      libavformat/matroskadec.c

@ -1258,13 +1258,23 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska,
case EBML_STOP: case EBML_STOP:
return 1; return 1;
default: default:
if (ffio_limit(pb, length) != length) { if (length) {
// ffio_limit emits its own error message, if (ffio_limit(pb, length) != length) {
// so we don't have to. // ffio_limit emits its own error message,
return AVERROR(EIO); // so we don't have to.
} return AVERROR(EIO);
res = avio_skip(pb, length); }
res = res < 0 ? res : 0; if ((res = avio_skip(pb, length - 1)) >= 0) {
// avio_skip might take us past EOF. We check for this
// by skipping only length - 1 bytes, reading a byte and
// checking the error flags. This is done in order to check
// that the element has been properly skipped even when
// no filesize (that ffio_limit relies on) is available.
avio_r8(pb);
res = NEEDS_CHECKING;
}
} else
res = 0;
} }
if (res) { if (res) {
if (res == NEEDS_CHECKING) { if (res == NEEDS_CHECKING) {

Loading…
Cancel
Save