From be74c35ba2da123d033a186fc5b5eacce0d6b224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Zumer?= Date: Sat, 25 Jan 2020 11:59:47 -0500 Subject: [PATCH] Fix files with short paths crashing the emulator The file path being loaded is dynamically replaced with an emulator-local copy stored in a SAVE directory, which allows the original disk data to remain unmodified. In case the original file path is shorter than the destination "save" path, the file name buffer was undersized in some situations, which could cause a crash on load. --- source/DiskImageHelper.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/DiskImageHelper.cpp b/source/DiskImageHelper.cpp index 80496e879..6a2172025 100644 --- a/source/DiskImageHelper.cpp +++ b/source/DiskImageHelper.cpp @@ -1746,7 +1746,9 @@ ImageError_e CImageHelperBase::Open( LPCTSTR pszImageFilename, !CopyFile(pszImageFilename, path, true)) return eIMAGE_ERROR_UNABLE_TO_OPEN; - ZeroMemory((void *) pszImageFilename, sizeof(pszImageFilename)); + // Do not delete pszImageFilename off the heap, as + // it seems that its contents are reused elsewhere. + pszImageFilename = new CHAR[MAX_PATH]; strcpy((char *) pszImageFilename, path); CloseHandle(pImageInfo->hFile); @@ -1763,14 +1765,14 @@ ImageError_e CImageHelperBase::Open( LPCTSTR pszImageFilename, // This omits some of the error detection done as part of CheckNormalFile(), // and assumes that the save copy matches the original. - delete[] pImageInfo->pImageBuffer; + delete [] pImageInfo->pImageBuffer; pImageInfo->pImageBuffer = new BYTE[pImageInfo->uImageSize]; DWORD dwBytesRead; BOOL bRes = ReadFile(pImageInfo->hFile, pImageInfo->pImageBuffer, pImageInfo->uImageSize, &dwBytesRead, NULL); if (!bRes || pImageInfo->uImageSize != dwBytesRead) { - delete[] pImageInfo->pImageBuffer; + delete [] pImageInfo->pImageBuffer; pImageInfo->pImageBuffer = NULL; return eIMAGE_ERROR_BAD_SIZE; }