Fix calculation bug in QWaveDecoder.
When comparing the size of the WaveHeader and the chunk size, we need to include the ID and Size fields, or any extra data won't be discarded and the parsing will fail. Change-Id: I730833f33f57b26cd750985354136191f7e7ce04 Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
This commit is contained in:
committed by
The Qt Project
parent
5ffe8bd6d9
commit
d64a68f5c8
@@ -153,13 +153,15 @@ void QWaveDecoder::handleData()
|
|||||||
chunk descriptor;
|
chunk descriptor;
|
||||||
peekChunk(&descriptor);
|
peekChunk(&descriptor);
|
||||||
|
|
||||||
if (source->bytesAvailable() < qint64(descriptor.size + sizeof(chunk)))
|
quint32 rawChunkSize = descriptor.size + sizeof(chunk);
|
||||||
|
if (source->bytesAvailable() < qint64(rawChunkSize))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
WAVEHeader wave;
|
WAVEHeader wave;
|
||||||
source->read(reinterpret_cast<char *>(&wave), sizeof(WAVEHeader));
|
source->read(reinterpret_cast<char *>(&wave), sizeof(WAVEHeader));
|
||||||
if (descriptor.size > sizeof(WAVEHeader))
|
|
||||||
discardBytes(descriptor.size - sizeof(WAVEHeader));
|
if (rawChunkSize > sizeof(WAVEHeader))
|
||||||
|
discardBytes(rawChunkSize - sizeof(WAVEHeader));
|
||||||
|
|
||||||
// Swizzle this
|
// Swizzle this
|
||||||
if (bigEndian) {
|
if (bigEndian) {
|
||||||
|
|||||||
BIN
tests/auto/unit/qwavedecoder/data/isawav_1_16_44100_le_2.wav
Normal file
BIN
tests/auto/unit/qwavedecoder/data/isawav_1_16_44100_le_2.wav
Normal file
Binary file not shown.
@@ -130,6 +130,8 @@ void tst_QWaveDecoder::file_data()
|
|||||||
QTest::newRow("File isawav_1_16_44100_le.wav") << testFilePath("isawav_1_16_44100_le.wav") << tst_QWaveDecoder::None << 1 << 16 << 44100 << QAudioFormat::LittleEndian;
|
QTest::newRow("File isawav_1_16_44100_le.wav") << testFilePath("isawav_1_16_44100_le.wav") << tst_QWaveDecoder::None << 1 << 16 << 44100 << QAudioFormat::LittleEndian;
|
||||||
QTest::newRow("File isawav_2_16_8000_be.wav") << testFilePath("isawav_2_16_8000_be.wav") << tst_QWaveDecoder::None << 2 << 16 << 8000 << QAudioFormat::BigEndian;
|
QTest::newRow("File isawav_2_16_8000_be.wav") << testFilePath("isawav_2_16_8000_be.wav") << tst_QWaveDecoder::None << 2 << 16 << 8000 << QAudioFormat::BigEndian;
|
||||||
QTest::newRow("File isawav_2_16_44100_be.wav") << testFilePath("isawav_2_16_44100_be.wav") << tst_QWaveDecoder::None << 2 << 16 << 44100 << QAudioFormat::BigEndian;
|
QTest::newRow("File isawav_2_16_44100_be.wav") << testFilePath("isawav_2_16_44100_be.wav") << tst_QWaveDecoder::None << 2 << 16 << 44100 << QAudioFormat::BigEndian;
|
||||||
|
// The next file has extra data in the wave header.
|
||||||
|
QTest::newRow("File isawav_1_16_44100_le_2.wav") << testFilePath("isawav_1_16_44100_le_2.wav") << tst_QWaveDecoder::None << 1 << 16 << 44100 << QAudioFormat::LittleEndian;
|
||||||
|
|
||||||
// 32 bit waves are not supported
|
// 32 bit waves are not supported
|
||||||
QTest::newRow("File isawav_1_32_8000_le.wav") << testFilePath("isawav_1_32_8000_le.wav") << tst_QWaveDecoder::FormatDescriptor << 1 << 32 << 8000 << QAudioFormat::LittleEndian;
|
QTest::newRow("File isawav_1_32_8000_le.wav") << testFilePath("isawav_1_32_8000_le.wav") << tst_QWaveDecoder::FormatDescriptor << 1 << 32 << 8000 << QAudioFormat::LittleEndian;
|
||||||
|
|||||||
Reference in New Issue
Block a user