d3c5aac6b309 — Chris Cannam a month ago
Report failure when mangled header results in no channels
1 files changed, 6 insertions(+), 1 deletions(-)

M src/MiniMP3ReadStream.cpp
M src/MiniMP3ReadStream.cpp +6 -1
@@ 91,6 91,11 @@ MiniMP3ReadStream::MiniMP3ReadStream(std
     m_channelCount = m_d->dec.info.channels;
     m_sampleRate = m_d->dec.info.hz;
 
+    if (m_channelCount == 0) {
+        m_error = "MiniMP3ReadStream: Unable to open file: bad header or no channels reported";
+        throw InvalidFileFormat(m_path, "bad header or no channels reported");
+    }
+    
     if (m_channelCount > 0) {
         m_estimatedFrameCount = m_d->dec.samples / m_channelCount;
     } else {

          
@@ 101,7 106,7 @@ MiniMP3ReadStream::MiniMP3ReadStream(std
 size_t
 MiniMP3ReadStream::getFrames(size_t count, float *frames)
 {
-    if (m_error != "") return 0;
+    if (m_error != "" || m_channelCount == 0) return 0;
     if (count == 0) return 0;
 
 //    cerr << "getFrames: working" << endl;