diff options
author | Johannes Schickel | 2012-01-26 02:41:26 +0100 |
---|---|---|
committer | Johannes Schickel | 2012-01-26 02:43:58 +0100 |
commit | 86a4bbbd9bea1a1a7cbe109fbe57db913fb0d462 (patch) | |
tree | f7f7271396516c52e216b2a2fe8e45c405088a23 | |
parent | d620dd90bd5db3a1d40b53be6d395e5f2bcc04b7 (diff) | |
download | scummvm-rg350-86a4bbbd9bea1a1a7cbe109fbe57db913fb0d462.tar.gz scummvm-rg350-86a4bbbd9bea1a1a7cbe109fbe57db913fb0d462.tar.bz2 scummvm-rg350-86a4bbbd9bea1a1a7cbe109fbe57db913fb0d462.zip |
AUDIO: Add more warnings in case invalid VOC data is encountered.
-rw-r--r-- | audio/decoders/voc.cpp | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/audio/decoders/voc.cpp b/audio/decoders/voc.cpp index eb9c4e0c56..f0b5b2777d 100644 --- a/audio/decoders/voc.cpp +++ b/audio/decoders/voc.cpp @@ -332,8 +332,10 @@ void VocStream::preProcess() { block.length |= _stream->readByte() << 16; // Premature end of stream => error! - if (_stream->eos() || _stream->err()) + if (_stream->eos() || _stream->err()) { + warning("VocStream::preProcess: Reading failed"); return; + } uint32 skip = 0; @@ -343,17 +345,26 @@ void VocStream::preProcess() { // Sound data (New format) case 9: if (block.code == 1) { + if (block.length < 2) { + warning("Invalid sound data block length %d in VOC file", block.length); + return; + } + // Read header data int freqDiv = _stream->readByte(); // Prevent division through 0 - if (freqDiv == 256) + if (freqDiv == 256) { + warning("Invalid frequency divisor 256 in VOC file"); return; + } block.sampleBlock.rate = getSampleRateFromVOCRate(freqDiv); int codec = _stream->readByte(); // We only support 8bit PCM - if (codec != 0) + if (codec != 0) { + warning("Unhandled codec %d in VOC file", codec); return; + } block.sampleBlock.samples = skip = block.length - 2; block.sampleBlock.offset = _stream->pos(); @@ -371,11 +382,18 @@ void VocStream::preProcess() { } } } else { + if (block.length < 12) { + warning("Invalid sound data (wew format) block length %d in VOC file", block.length); + return; + } + block.sampleBlock.rate = _stream->readUint32LE(); int bitsPerSample = _stream->readByte(); // We only support 8bit PCM - if (bitsPerSample != 8) + if (bitsPerSample != 8) { + warning("Unhandled bits per sample %d in VOC file", bitsPerSample); return; + } int channels = _stream->readByte(); // We only support mono if (channels != 1) { @@ -400,23 +418,29 @@ void VocStream::preProcess() { // Silence case 3: { - if (block.length != 3) + if (block.length != 3) { + warning("Invalid silence block length %d in VOC file", block.length); return; + } block.sampleBlock.offset = 0; block.sampleBlock.samples = _stream->readUint16LE() + 1; int freqDiv = _stream->readByte(); // Prevent division through 0 - if (freqDiv == 256) + if (freqDiv == 256) { + warning("Invalid frequency divisor 256 in VOC file"); return; + } block.sampleBlock.rate = getSampleRateFromVOCRate(freqDiv); } break; // Repeat start case 6: - if (block.length != 2) + if (block.length != 2) { + warning("Invalid repeat start block length %d in VOC file", block.length); return; + } block.loopBlock.count = _stream->readUint16LE() + 1; break; @@ -432,8 +456,10 @@ void VocStream::preProcess() { int freqDiv = _stream->readUint16LE(); // Prevent division through 0 - if (freqDiv == 65536) + if (freqDiv == 65536) { + warning("Invalid frequency divisor 65536 in VOC file"); return; + } int codec = _stream->readByte(); // We only support RAW 8bit PCM. @@ -460,8 +486,10 @@ void VocStream::preProcess() { } // Premature end of stream => error! - if (_stream->eos() || _stream->err()) + if (_stream->eos() || _stream->err()) { + warning("VocStream::preProcess: Reading failed"); return; + } // Skip the rest of the block if (skip) |