History

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. ---

Ulrik committed 3 years ago

Commit 95314cd1 parent 399234e1 file · +12 −4Browse files

Unified · Split

libavformat/flacdec.c+12−4
@@ -80,8 +80,13 @@ static int flac_read_header(AVFormatContext *s) · 79 unmodified lines
8080
8181 /* process metadata blocks */
8282 while (!avio_feof(s->pb) && !metadata_last) {
83− if (avio_read(s->pb, header, 4) != 4)
84− return AVERROR_INVALIDDATA;
83+ ret = avio_read(s->pb, header, 4);
84+ if (ret < 0) {
85+ return ret;
86+ } else if (ret != 4) {
87+ return AVERROR_EOF;
88+ }
89+
8590 flac_parse_block_header(header, &metadata_last, &metadata_type,
8691 &metadata_size);
8792 switch (metadata_type) {
@@ -95,8 +100,11 @@ static int flac_read_header(AVFormatContext *s) · 7 unmodified lines
95100 if (!buffer) {
96101 return AVERROR(ENOMEM);
97102 }
98− if (avio_read(s->pb, buffer, metadata_size) != metadata_size) {
99− RETURN_ERROR(AVERROR(EIO));
103+ ret = avio_read(s->pb, buffer, metadata_size);
104+ if (ret < 0) {
105+ RETURN_ERROR(ret);
106+ } else if (ret != metadata_size) {
107+ RETURN_ERROR(AVERROR_EOF);
100108 }
101109 break;
102110 /* skip metadata block for unsupported types */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t