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
80 80
81 /* process metadata blocks */81 /* process metadata blocks */
82 while (!avio_feof(s->pb) && !metadata_last) {82 while (!avio_feof(s->pb) && !metadata_last) {
83 if (avio_read(s->pb, header, 4) != 4)83 ret = avio_read(s->pb, header, 4);
84 return AVERROR_INVALIDDATA;84 if (ret < 0) {
85 return ret;
86 } else if (ret != 4) {
87 return AVERROR_EOF;
88 }
89
85 flac_parse_block_header(header, &metadata_last, &metadata_type,90 flac_parse_block_header(header, &metadata_last, &metadata_type,
86 &metadata_size);91 &metadata_size);
87 switch (metadata_type) {92 switch (metadata_type) {
@@ -95,8 +100,11 @@ static int flac_read_header(AVFormatContext *s) · 7 unmodified lines
95 if (!buffer) {100 if (!buffer) {
96 return AVERROR(ENOMEM);101 return AVERROR(ENOMEM);
97 }102 }
98 if (avio_read(s->pb, buffer, metadata_size) != metadata_size) {103 ret = avio_read(s->pb, buffer, metadata_size);
99 RETURN_ERROR(AVERROR(EIO));104 if (ret < 0) {
105 RETURN_ERROR(ret);
106 } else if (ret != metadata_size) {
107 RETURN_ERROR(AVERROR_EOF);
100 }108 }
101 break;109 break;
102 /* skip metadata block for unsupported types */110 /* 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