Fix file-extension check

If the extension is not found, string::rfind() returns -1,
That can still match unrelated file if the file-name is one
char longer than an arbitrary extension.

eg. "foo" matched ".aiff" because
-1 = strlen("foo") - strlen(".aiff")

Also due to a missing comma ".VOC.vwe" matched any file shorter
than 7 chars in length.
This commit is contained in:
Robin Gareus 2021-12-16 19:06:08 +01:00
parent 9f7114f761
commit 6b6ae5dedb
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 5 additions and 3 deletions

View File

@ -331,7 +331,7 @@ AudioFileSource::safe_audio_file_extension(const string& file)
".smp", ".SMP",
".snd", ".SND",
".maud", ".MAUD",
".voc", ".VOC"
".voc", ".VOC",
".vwe", ".VWE",
".w64", ".W64",
".wav", ".WAV",
@ -352,7 +352,8 @@ AudioFileSource::safe_audio_file_extension(const string& file)
};
for (size_t n = 0; n < sizeof(suffixes)/sizeof(suffixes[0]); ++n) {
if (file.rfind (suffixes[n]) == file.length() - strlen (suffixes[n])) {
size_t pos = file.rfind (suffixes[n]);
if (pos > 0 && pos == file.length() - strlen(suffixes[n])) {
return true;
}
}

View File

@ -85,7 +85,8 @@ FFMPEGFileSource::safe_audio_file_extension (const std::string &file)
};
for (size_t n = 0; n < sizeof(suffixes) / sizeof(suffixes[0]); ++n) {
if (file.rfind(suffixes[n]) == file.length() - strlen(suffixes[n])) {
size_t pos = file.rfind (suffixes[n]);
if (pos > 0 && pos == file.length() - strlen(suffixes[n])) {
return true;
}
}