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. ---
Unified · Split
| @@ -80,8 +80,13 @@ static int flac_read_header(AVFormatContext *s) · 79 unmodified lines | ||
| 80 | 80 | |
| 81 | 81 | /* process metadata blocks */ |
| 82 | 82 | 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 | + | |
| 85 | 90 | flac_parse_block_header(header, &metadata_last, &metadata_type, |
| 86 | 91 | &metadata_size); |
| 87 | 92 | switch (metadata_type) { |
| @@ -95,8 +100,11 @@ static int flac_read_header(AVFormatContext *s) · 7 unmodified lines | ||
| 95 | 100 | if (!buffer) { |
| 96 | 101 | return AVERROR(ENOMEM); |
| 97 | 102 | } |
| 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); | |
| 100 | 108 | } |
| 101 | 109 | break; |
| 102 | 110 | /* skip metadata block for unsupported types */ |