summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2021-01-16 15:35:28 +1100
committerDamien Zammit <damien@zamaudio.com>2021-01-16 15:41:00 +1100
commit232ba2575316a132a3fa977aa096904afe8e979d (patch)
treef1c74d7d9176bf64c4c3877b94f1c2ea407971df
parent26d30c29321100fd4789cce7956b966770f98817 (diff)
v10+: Fix segfault when wav list cannot be read due to .size() always 4
std::string() was initialised with a fixed size of 4, so checking for .size() == 0 will always fail. This fixes the _audiofiles vector from being iterated over when empty, and returns a PARSE FAIL when there are known to be wavs present but none were found.
-rw-r--r--ptformat.cc15
1 files changed, 12 insertions, 3 deletions
diff --git a/ptformat.cc b/ptformat.cc
index 85bc1a5..ca7f74d 100644
--- a/ptformat.cc
+++ b/ptformat.cc
@@ -665,7 +665,8 @@ PTFFormat::parsestring (uint32_t pos) {
bool
PTFFormat::parseaudio(void) {
bool found = false;
- uint32_t nwavs, i, n;
+ uint32_t nwavs = 0;
+ uint32_t i, n;
uint32_t pos = 0;
std::string wavtype;
std::string wavname;
@@ -680,7 +681,6 @@ PTFFormat::parseaudio(void) {
for (vector<PTFFormat::block_t>::iterator c = b->child.begin();
c != b->child.end(); ++c) {
if (c->content_type == 0x103a) {
- found = true;
//nstrings = u_endian_read4(&_ptfunxored[c->offset+1], is_bigendian);
pos = c->offset + 11;
// Found wav list
@@ -706,7 +706,7 @@ PTFFormat::parseaudio(void) {
continue;
}
} else {
- if (wavtype.size() != 0) {
+ if (wavtype[0] != '\0') {
if (!(foundin(wavtype, std::string("WAVE")) ||
foundin(wavtype, std::string("EVAW")) ||
foundin(wavtype, std::string("AIFF")) ||
@@ -718,6 +718,7 @@ PTFFormat::parseaudio(void) {
continue;
}
}
+ found = true;
wav_t f (n);
f.filename = wavname;
n++;
@@ -728,6 +729,14 @@ PTFFormat::parseaudio(void) {
}
}
+ if (!found) {
+ if (nwavs > 0) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
// Add wav length information
for (vector<PTFFormat::block_t>::iterator b = blocks.begin();
b != blocks.end(); ++b) {