mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2026-06-16 04:32:47 +02:00
[Wave] Fix issues with unaligned metadata chunks.
Fixes corruption issues with the sample in this PR. Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
This commit is contained in:
committed by
Daniel Verkamp
parent
188461be10
commit
5bbc00c05d
+13
-8
@@ -131,11 +131,11 @@ static int64_t next_tag(AVIOContext *pb, uint32_t *tag, int big_endian)
|
||||
}
|
||||
|
||||
/* RIFF chunks are always at even offsets relative to where they start. */
|
||||
static int64_t wav_seek_tag(WAVDemuxContext * wav, AVIOContext *s, int64_t offset, int whence)
|
||||
static int64_t wav_seek_tag(WAVDemuxContext * wav, AVIOContext *s, int64_t offset)
|
||||
{
|
||||
offset += offset < INT64_MAX && offset + wav->unaligned & 1;
|
||||
|
||||
return avio_seek(s, offset, whence);
|
||||
return avio_seek(s, offset, SEEK_SET);
|
||||
}
|
||||
|
||||
/* return the size of the found tag */
|
||||
@@ -144,13 +144,16 @@ static int64_t find_tag(WAVDemuxContext * wav, AVIOContext *pb, uint32_t tag1)
|
||||
unsigned int tag;
|
||||
int64_t size;
|
||||
|
||||
if (avio_tell(pb) + wav->unaligned & 1)
|
||||
avio_skip(pb, 1);
|
||||
|
||||
for (;;) {
|
||||
if (avio_feof(pb))
|
||||
return AVERROR_EOF;
|
||||
size = next_tag(pb, &tag, wav->rifx);
|
||||
if (tag == tag1)
|
||||
break;
|
||||
wav_seek_tag(wav, pb, size, SEEK_CUR);
|
||||
avio_skip(pb, size + (size & 1));
|
||||
}
|
||||
return size;
|
||||
}
|
||||
@@ -422,7 +425,7 @@ static int wav_read_header(AVFormatContext *s)
|
||||
for (;;) {
|
||||
AVStream *vst;
|
||||
size = next_tag(pb, &tag, wav->rifx);
|
||||
next_tag_ofs = avio_tell(pb) + size;
|
||||
next_tag_ofs = avio_tell(pb) + size + (size & 1);
|
||||
|
||||
if (avio_feof(pb))
|
||||
break;
|
||||
@@ -454,10 +457,12 @@ static int wav_read_header(AVFormatContext *s)
|
||||
}
|
||||
|
||||
if (rf64 || bw64) {
|
||||
next_tag_ofs = wav->data_end = av_sat_add64(avio_tell(pb), data_size);
|
||||
} else if (size != 0xFFFFFFFF) {
|
||||
wav->data_end = av_sat_add64(avio_tell(pb), data_size);
|
||||
next_tag_ofs = wav->data_end + (data_size & 1);
|
||||
} else if (size > 0 && size != 0xFFFFFFFF) {
|
||||
data_size = size;
|
||||
next_tag_ofs = wav->data_end = size ? next_tag_ofs : INT64_MAX;
|
||||
wav->data_end = avio_tell(pb) + size;
|
||||
next_tag_ofs = wav->data_end + (size & 1);
|
||||
} else {
|
||||
av_log(s, AV_LOG_WARNING, "Ignoring maximum wav data size, "
|
||||
"file may be invalid\n");
|
||||
@@ -599,7 +604,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)) ||
|
||||
wav_seek_tag(wav, pb, next_tag_ofs, SEEK_SET) < 0) {
|
||||
wav_seek_tag(wav, pb, next_tag_ofs) < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user