diff options
-rw-r--r-- | engines/draci/sound.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/engines/draci/sound.cpp b/engines/draci/sound.cpp index 106167ef8a..d534f46a6e 100644 --- a/engines/draci/sound.cpp +++ b/engines/draci/sound.cpp @@ -67,8 +67,12 @@ void LegacySoundArchive::openArchive(const char *path) { debugC(1, kDraciArchiverDebugLevel, "Loading header"); uint totalLength = _f->readUint32LE(); + const uint kMaxSamples = 4095; // The no-sound file is exactly 16K bytes long, so don't fail on short reads - uint sampleStarts[kMaxSamples]; + uint *sampleStarts = (uint *)malloc(kMaxSamples * sizeof(uint)); + if (!sampleStarts) + error("[LegacySoundArchive::openArchive] Cannot allocate buffer for no-sound file"); + for (uint i = 0; i < kMaxSamples; ++i) { sampleStarts[i] = _f->readUint32LE(); } @@ -90,17 +94,22 @@ void LegacySoundArchive::openArchive(const char *path) { } if (_samples[_sampleCount-1]._offset + _samples[_sampleCount-1]._length != totalLength && _samples[_sampleCount-1]._offset + _samples[_sampleCount-1]._length - _samples[0]._offset != totalLength) { - // WORKAROUND: the stored length is stored with the header for sounds and without the hader for dubbing. Crazy. + // WORKAROUND: the stored length is stored with the header for sounds and without the header for dubbing. Crazy. debugC(1, kDraciArchiverDebugLevel, "Broken sound archive: %d != %d", _samples[_sampleCount-1]._offset + _samples[_sampleCount-1]._length, totalLength); closeArchive(); + + free(sampleStarts); + return; } } else { debugC(1, kDraciArchiverDebugLevel, "Archive info: empty"); } + free(sampleStarts); + // Indicate that the archive has been successfully opened _opened = true; } |