From 4728735acf20fba24d0d03ab431160e250325869 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 28 Oct 2013 23:01:13 +0100 Subject: [PATCH] decoder/dsf: don't play junk at the end of the "data" chunk --- NEWS | 1 + src/decoder/DsfDecoderPlugin.cxx | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 488f13323..e1d23428d 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,7 @@ ver 0.18 (2012/??/??) - lastfm: remove defunct Last.fm support * decoder: - adplug: new decoder plugin using libadplug + - dsf: don't play junk at the end of the "data" chunk - ffmpeg: drop support for pre-0.8 ffmpeg - flac: require libFLAC 1.2 or newer - flac: support FLAC files inside archives diff --git a/src/decoder/DsfDecoderPlugin.cxx b/src/decoder/DsfDecoderPlugin.cxx index a7e2f3d1e..7f47074ee 100644 --- a/src/decoder/DsfDecoderPlugin.cxx +++ b/src/decoder/DsfDecoderPlugin.cxx @@ -156,12 +156,20 @@ dsf_read_metadata(Decoder *decoder, InputStream &is, data_size -= sizeof(data_chunk); - metadata->chunk_size = data_size; /* data_size cannot be bigger or equal to total file size */ const uint64_t size = (uint64_t)is.GetSize(); if (data_size >= size) return false; + /* use the sample count from the DSF header as the upper + bound, because some DSF files contain junk at the end of + the "data" chunk */ + const uint64_t samplecnt = dsf_fmt_chunk.scnt.Read(); + const uint64_t playable_size = samplecnt * 2 / 8; + if (data_size > playable_size) + data_size = playable_size; + + metadata->chunk_size = data_size; metadata->channels = (unsigned) dsf_fmt_chunk.channelnum; metadata->sample_rate = samplefreq; #ifdef HAVE_ID3TAG