aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorJulien2011-06-06 01:10:09 +0800
committerJulien2011-06-23 15:11:38 +0800
commite610a17fc3c8956aaca4b1f68a73dbfaebb5beb0 (patch)
tree36224468d7c317093d7347db128f1b46aff2916e /engines
parent9ff993382e17d1d7aef96105ad5fa2fe35043b7a (diff)
downloadscummvm-rg350-e610a17fc3c8956aaca4b1f68a73dbfaebb5beb0.tar.gz
scummvm-rg350-e610a17fc3c8956aaca4b1f68a73dbfaebb5beb0.tar.bz2
scummvm-rg350-e610a17fc3c8956aaca4b1f68a73dbfaebb5beb0.zip
DRACI: Allocate no-sound buffer on the heap in LegacySoundArchive::openArchive()
Diffstat (limited to 'engines')
-rw-r--r--engines/draci/sound.cpp13
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;
}