MultipartFileReader: Fix use-after-free when opening multipart files

Also fixes loading uppercase filenames on Linux.
This commit is contained in:
Connor McLaughlin 2022-05-24 18:05:04 +10:00 committed by refractionpcsx2
parent f2713462cc
commit 8bbcb05303
2 changed files with 13 additions and 6 deletions

View File

@ -262,10 +262,7 @@ bool InputIsoFile::Open(std::string srcfile, bool testOnly)
m_reader->SetBlockSize(m_blocksize);
// Returns the original reader if single-part or a Multipart reader otherwise
AsyncFileReader* m_reader_old = m_reader;
m_reader = MultipartFileReader::DetectMultipart(m_reader);
if (m_reader != m_reader_old) // Not the same object the old one need to be deleted
delete m_reader_old;
}
m_blocks = m_reader->GetBlockCount();

View File

@ -22,7 +22,7 @@
// Tests for a filename extension in both upper and lower case, if the filesystem happens
// to be case-sensitive.
static bool pxFileExists_WithExt( const std::string& filename, const std::string& ext )
static bool pxFileExists_WithExt( std::string& filename, const std::string& ext )
{
std::string temp(Path::ReplaceExtension(filename, StringUtil::toLower(ext)));
if (FileSystem::FileExists(temp.c_str()))
@ -31,7 +31,11 @@ static bool pxFileExists_WithExt( const std::string& filename, const std::string
#if defined(_WIN32) || defined(__DARWIN__)
temp = Path::ReplaceExtension(filename, StringUtil::toUpper(ext));
if (FileSystem::FileExists(temp.c_str()))
{
// make sure we open the correct one
filename = std::move(temp);
return true;
}
#endif
return false;
@ -114,11 +118,17 @@ void MultipartFileReader::FindParts()
break;
Part* thispart = m_parts + m_numparts;
AsyncFileReader* thisreader = thispart->reader = new FlatFileReader();
AsyncFileReader* thisreader = new FlatFileReader();
if (!thisreader->Open(nameparts))
{
delete thisreader;
break;
}
thisreader->Open(nameparts);
thisreader->SetBlockSize(bsize);
thispart->reader = thisreader;
thispart->start = blocks;
uint bcount = thisreader->GetBlockCount();