COMMON: Avoid scanning out of game directory for AppleDouble files. Bug #15016

Also implement sanity check for paths containing drive, e.g. "Games:" on Amiga
or "D:" on Windows.
This commit is contained in:
Eugene Sandulenko 2024-11-12 01:08:59 +01:00
parent c6daf24573
commit 754827c68d
No known key found for this signature in database
GPG Key ID: 014D387312D34F08

View File

@ -174,13 +174,24 @@ SeekableReadStream *MacResManager::openAppleDoubleWithAppleOrOSXNaming(Archive&
return stream;
const ArchiveMemberPtr archiveMember = archive.getMember(fileName);
const Common::FSNode *plainFsNode = dynamic_cast<const Common::FSNode *>(archiveMember.get());
const Common::FSNode *plainFsNode = dynamic_cast<const Common::FSNode *>(archiveMember.get());
// Try finding __MACOSX
Common::StringArray components = (plainFsNode ? plainFsNode->getPath() : fileName).splitComponents();
// We do not need to look beyond the root directory
// Fixes bug #15016
int start = MAX((int)components.size() - fileName.numComponents(), 0);
if (components.empty() || components[components.size() - 1].empty())
return nullptr;
for (int i = components.size() - 1; i >= 0; i--) {
for (int i = components.size() - 1; i >= start; i--) {
// On Windows and Amiga we may have disk name followed
// by ':'. So, checking for that. Otherwise, we will generate
// paths like "__MACOSX:D/Games/._Data"
if (i == 0 && components[i].contains(':'))
break;
Common::StringArray newComponents;
int j;
for (j = 0; j < i; j++)