[FFmpeg-cvslog] avformat/flacdec: Return correct error-codes on read-failure
Ulrik
git at videolan.org
Wed Feb 26 16:18:40 EET 2025
ffmpeg | branch: master | Ulrik <ulrikm at spotify.com> | Thu Jan 26 17:51:02 2023 +0100| [95314cd7c5c0d2dc884c245583b697db590cfefd] | committer: Tomas Härdin
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.
---
Tomas: changed to use AVERROR_EOF
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=95314cd7c5c0d2dc884c245583b697db590cfefd
---
libavformat/flacdec.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 3c317acaee..1c18556c3d 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -80,8 +80,13 @@ 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 < 0) {
+ return ret;
+ } else if (ret != 4) {
+ return AVERROR_EOF;
+ }
+
flac_parse_block_header(header, &metadata_last, &metadata_type,
&metadata_size);
switch (metadata_type) {
@@ -95,8 +100,11 @@ 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 < 0) {
+ RETURN_ERROR(ret);
+ } else if (ret != metadata_size) {
+ RETURN_ERROR(AVERROR_EOF);
}
break;
/* skip metadata block for unsupported types */
More information about the ffmpeg-cvslog
mailing list