From a41b32bbb296fa5c2b22c531a502796e2552c221 Mon Sep 17 00:00:00 2001 From: "Stephen F. Booth" Date: Thu, 28 Jul 2011 08:36:14 -0400 Subject: [PATCH] Don't crash when wav files have a 0 for bit per channel (sampleWidth) I've seen this in a wav that has an audio format of MP3 (0x55) --- taglib/riff/aiff/aiffproperties.cpp | 2 +- taglib/riff/wav/wavproperties.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/taglib/riff/aiff/aiffproperties.cpp b/taglib/riff/aiff/aiffproperties.cpp index 4a1a3001..0ef9c239 100644 --- a/taglib/riff/aiff/aiffproperties.cpp +++ b/taglib/riff/aiff/aiffproperties.cpp @@ -156,5 +156,5 @@ void RIFF::AIFF::Properties::read(const ByteVector &data) double sampleRate = ConvertFromIeeeExtended(reinterpret_cast(data.mid(8, 10).data())); d->sampleRate = sampleRate; d->bitrate = (sampleRate * d->sampleWidth * d->channels) / 1000.0; - d->length = d->sampleFrames / d->sampleRate; + d->length = d->sampleRate > 0 ? d->sampleFrames / d->sampleRate : 0; } diff --git a/taglib/riff/wav/wavproperties.cpp b/taglib/riff/wav/wavproperties.cpp index 10d10eca..c8b7fd6b 100644 --- a/taglib/riff/wav/wavproperties.cpp +++ b/taglib/riff/wav/wavproperties.cpp @@ -124,5 +124,6 @@ void RIFF::WAV::Properties::read(const ByteVector &data) d->bitrate = byteRate * 8 / 1000; d->length = byteRate > 0 ? d->streamLength / byteRate : 0; - d->sampleFrames = d->streamLength / (d->channels * (d->sampleWidth / 8)); + if(d->channels > 0 && d->sampleWidth > 0) + d->sampleFrames = d->streamLength / (d->channels * (d->sampleWidth / 8)); }