History

avformat/matroskadec: Add a workaround for missing WavPack extradata

mkvmerge versions 6.2 to 40.0 had a bug that made it not propagate the WavPack extradata (containing the WavPack version) during remuxing from a Matroska file; currently our demuxer would treat every WavPack block encountered as invalid data (unless the WavPack stream is to be discarded (i.e. the streams discard is >= AVDISCARD_ALL)) and try to resync to the next level 1 element. Luckily, the WavPack version is currently not really important; so we fix this problem by assuming a version. David Bryant, the creator of WavPack, recommended using version 0x410 (the most recent version) for this. And this is what this commit does. A FATE-test for this has been added.

Andreas Rheinhardt committed 6 years ago

Commit 048bc3f1 parent ad91cf13 files · +24 −1Browse files

Showing the changes to libavformat (1 of 3 files). Show all

Unified · Split

libavformat/matroskadec.c+10−1
@@ -2613,6 +2613,14 @@ static int matroska_parse_tracks(AVFormatContext *s) · 2612 unmodified lines
26132613 ret = matroska_parse_flac(s, track, &extradata_offset);
26142614 if (ret < 0)
26152615 return ret;
2616+ } else if (codec_id == AV_CODEC_ID_WAVPACK && track->codec_priv.size < 2) {
2617+ av_log(matroska->ctx, AV_LOG_INFO, "Assuming WavPack version 4.10 "
2618+ "in absence of valid CodecPrivate.\n");
2619+ extradata_size = 2;
2620+ extradata = av_mallocz(2 + AV_INPUT_BUFFER_PADDING_SIZE);
2621+ if (!extradata)
2622+ return AVERROR(ENOMEM);
2623+ AV_WL16(extradata, 0x410);
26162624 } else if (codec_id == AV_CODEC_ID_PRORES && track->codec_priv.size == 4) {
26172625 fourcc = AV_RL32(track->codec_priv.data);
26182626 } else if (codec_id == AV_CODEC_ID_VP9 && track->codec_priv.size) {
@@ -3165,9 +3173,10 @@ static int matroska_parse_wavpack(MatroskaTrack *track, uint8_t *src, · 546 unmodified lines
31653173 uint16_t ver;
31663174 int ret, offset = 0;
31673175
3168− if (srclen < 12 || track->stream->codecpar->extradata_size < 2)
3176+ if (srclen < 12)
31693177 return AVERROR_INVALIDDATA;
31703178
3179+ av_assert1(track->stream->codecpar->extradata_size >= 2);
31713180 ver = AV_RL16(track->stream->codecpar->extradata);
31723181
31733182 samples = AV_RL32(src);

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