From: "Tomas Härdin" <git@haerdin.se> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH 4/8] avformat/flacdec: Return correct error-codes on read-failure Date: Wed, 05 Feb 2025 15:20:30 +0100 Message-ID: <1f41aeb9976efbcd2930a039418d27f7307ed757.camel@haerdin.se> (raw) In-Reply-To: <f4713629c8248e1c33e109b919d6149a3a1f4c82.camel@haerdin.se> [-- Attachment #1: Type: text/plain, Size: 1 bytes --] [-- Attachment #2: 0004-avformat-flacdec-Return-correct-error-codes-on-read-.patch --] [-- Type: text/x-patch, Size: 2241 bytes --] From c81e350d5419cf02f029ce006d94f257bc18fb97 Mon Sep 17 00:00:00 2001 From: Ulrik <ulrikm@spotify.com> Date: Thu, 26 Jan 2023 17:51:02 +0100 Subject: [PATCH 4/8] 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 --- libavformat/flacdec.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index 9f65c25864..77dcc620a4 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -81,8 +81,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) { @@ -96,8 +101,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 */ -- 2.39.5 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2025-02-05 14:20 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-02-05 14:18 [FFmpeg-devel] [PATCH 1/8] avformat/http: Return EIO for prematurely broken connection Tomas Härdin 2025-02-05 14:19 ` [FFmpeg-devel] [PATCH 2/8] libavcodec/wmadec: Return AVERROR_INVALIDDATA on decoding errors Tomas Härdin 2025-02-05 16:28 ` Marth64 2025-02-05 14:20 ` [FFmpeg-devel] [PATCH 3/8] libavformat/flacdec: Export samples md5 as metadata Tomas Härdin 2025-02-05 14:20 ` Tomas Härdin [this message] 2025-02-05 14:21 ` [FFmpeg-devel] [PATCH 5/8] rtmp: Set correct message stream id when writing as server Tomas Härdin 2025-02-05 14:22 ` [FFmpeg-devel] [PATCH 6/8] GOL-1361: Remove invalid CTTS sample_offset check Tomas Härdin 2025-02-05 14:23 ` [FFmpeg-devel] [PATCH 7/8] avformat/mp3dec: Subtract known padding from duration Tomas Härdin 2025-02-05 14:24 ` [FFmpeg-devel] [PATCH 8/8] Make mime-type award a bonus probe score Tomas Härdin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1f41aeb9976efbcd2930a039418d27f7307ed757.camel@haerdin.se \ --to=git@haerdin.se \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git