Reasonable enough. Might want a sample Spotify comments ---------------- Unexpected EOF is treated as invalid data
/Tomas
From 4d803c5f5c13e194a0e52d287f021b73ec7172bd Mon Sep 17 00:00:00 2001 From: Ulrik <ulr...@spotify.com> Date: Thu, 26 Jan 2023 17:51:02 +0100 Subject: [PATCH 11/15] avformat/flacdec:Return correct error-codes on read-failure Forward errors from `avio_read` directly. When `avio_read` sees EOF before expected bytes can be read, consistently return `AVERROR_INVALIDDATA` We used to return `AVERROR(AVERROR_INVALIDDATA)` when failing to read metadata block headers. `AVERROR_INVALIDDATA` is already negative, so wrapping in `AVERROR` leads to double-negation. We used to return `AVERROR(EIO)` when failing to read extended metadata. However, many times, the IO-layer is not at fault, the input data is simply corrupted (truncated), so we return `AVERROR_INVALIDDATA` here as well. --- libavformat/flacdec.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index 9f65c25864..be305fec82 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -81,8 +81,15 @@ static int flac_read_header(AVFormatContext *s) /* process metadata blocks */ while (!avio_feof(s->pb) && !metadata_last) { - if (avio_read(s->pb, header, 4) != 4) - return AVERROR_INVALIDDATA; + ret = avio_read(s->pb, header, 4); + if (ret != 4) { + if (ret < 0) { + goto fail; + } else { + return AVERROR_INVALIDDATA; + } + } + flac_parse_block_header(header, &metadata_last, &metadata_type, &metadata_size); switch (metadata_type) { @@ -96,8 +103,13 @@ static int flac_read_header(AVFormatContext *s) if (!buffer) { return AVERROR(ENOMEM); } - if (avio_read(s->pb, buffer, metadata_size) != metadata_size) { - RETURN_ERROR(AVERROR(EIO)); + ret = avio_read(s->pb, buffer, metadata_size); + if (ret != metadata_size) { + if (ret < 0) { + goto fail; + } else { + RETURN_ERROR(AVERROR_INVALIDDATA); + } } break; /* skip metadata block for unsupported types */ -- 2.39.2
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".