X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fwavdec.c;h=f65a66a0066b424468945e0be88b55106c086c91;hb=8b2e9636c57b22582143467a8a06b509b47b92f9;hp=07df9232d783f6db63f8bde187317a594e2744d8;hpb=a5f8873620ce502d37d0cc3ef93ada2ea8fb8de7;p=ffmpeg diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index 07df9232d78..f65a66a0066 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -23,6 +23,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include "libavutil/avassert.h" #include "libavutil/dict.h" #include "libavutil/log.h" @@ -49,6 +51,12 @@ static int64_t next_tag(AVIOContext *pb, uint32_t *tag) return avio_rl32(pb); } +/* RIFF chunks are always on a even offset. */ +static int64_t wav_seek_tag(AVIOContext *s, int64_t offset, int whence) +{ + return avio_seek(s, offset + (offset & 1), whence); +} + /* return the size of the found tag */ static int64_t find_tag(AVIOContext *pb, uint32_t tag1) { @@ -61,7 +69,7 @@ static int64_t find_tag(AVIOContext *pb, uint32_t tag1) size = next_tag(pb, &tag); if (tag == tag1) break; - avio_skip(pb, size); + wav_seek_tag(pb, size, SEEK_CUR); } return size; } @@ -219,18 +227,18 @@ static int wav_read_header(AVFormatContext *s) rf64 = tag == MKTAG('R', 'F', '6', '4'); if (!rf64 && tag != MKTAG('R', 'I', 'F', 'F')) - return -1; + return AVERROR_INVALIDDATA; avio_rl32(pb); /* file size */ tag = avio_rl32(pb); if (tag != MKTAG('W', 'A', 'V', 'E')) - return -1; + return AVERROR_INVALIDDATA; if (rf64) { if (avio_rl32(pb) != MKTAG('d', 's', '6', '4')) - return -1; + return AVERROR_INVALIDDATA; size = avio_rl32(pb); if (size < 16) - return -1; + return AVERROR_INVALIDDATA; avio_rl64(pb); /* RIFF size */ data_size = avio_rl64(pb); @@ -307,7 +315,7 @@ static int wav_read_header(AVFormatContext *s) /* seek to next tag unless we know that we'll run into EOF */ if ((avio_size(pb) > 0 && next_tag_ofs >= avio_size(pb)) || - avio_seek(pb, next_tag_ofs, SEEK_SET) < 0) { + wav_seek_tag(pb, next_tag_ofs, SEEK_SET) < 0) { break; } } @@ -467,22 +475,22 @@ static int w64_read_header(AVFormatContext *s) avio_read(pb, guid, 16); if (memcmp(guid, guid_riff, 16)) - return -1; + return AVERROR_INVALIDDATA; /* riff + wave + fmt + sizes */ if (avio_rl64(pb) < 16 + 8 + 16 + 8 + 16 + 8) - return -1; + return AVERROR_INVALIDDATA; avio_read(pb, guid, 16); if (memcmp(guid, guid_wave, 16)) { av_log(s, AV_LOG_ERROR, "could not find wave guid\n"); - return -1; + return AVERROR_INVALIDDATA; } size = find_guid(pb, guid_fmt); if (size < 0) { av_log(s, AV_LOG_ERROR, "could not find fmt guid\n"); - return -1; + return AVERROR_INVALIDDATA; } st = avformat_new_stream(s, NULL); @@ -502,7 +510,7 @@ static int w64_read_header(AVFormatContext *s) size = find_guid(pb, guid_data); if (size < 0) { av_log(s, AV_LOG_ERROR, "could not find data guid\n"); - return -1; + return AVERROR_INVALIDDATA; } wav->data_end = avio_tell(pb) + size - 24; wav->w64 = 1;