]> granicus.if.org Git - taglib/commitdiff
Don't crash when wav files have a 0 for bit per channel (sampleWidth)
authorStephen F. Booth <me@sbooth.org>
Thu, 28 Jul 2011 12:36:14 +0000 (08:36 -0400)
committerStephen F. Booth <me@sbooth.org>
Thu, 28 Jul 2011 12:36:14 +0000 (08:36 -0400)
I've seen this in a wav that has an audio format of MP3 (0x55)

taglib/riff/aiff/aiffproperties.cpp
taglib/riff/wav/wavproperties.cpp

index 4a1a3001388fdd976e5446103ca7fbf2f375f27a..0ef9c23944cbcab3563cbeeca7094ffe2e3819f7 100644 (file)
@@ -156,5 +156,5 @@ void RIFF::AIFF::Properties::read(const ByteVector &data)
   double sampleRate = ConvertFromIeeeExtended(reinterpret_cast<unsigned char *>(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;
 }
index 10d10eca58b8dcfbbd3ff0211a5b4fae007303b7..c8b7fd6b9a44ae995696f43542d3a3713a2a0388 100644 (file)
@@ -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));
 }