From 521e2cad4cdfe4d5828a260a574f60fc7f7943b0 Mon Sep 17 00:00:00 2001 From: rh101 Date: Sun, 25 Apr 2021 12:15:56 +1000 Subject: [PATCH] Verify the amount of string space we have to replace the zip extension --- cocos/base/ZipUtils.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cocos/base/ZipUtils.cpp b/cocos/base/ZipUtils.cpp index 4dc823290c..68a2186ba5 100644 --- a/cocos/base/ZipUtils.cpp +++ b/cocos/base/ZipUtils.cpp @@ -569,9 +569,10 @@ voidpf ZipFile_opendisk_file_func(voidpf opaque, voidpf stream, uint32_t number_ if (pos != std::string::npos && pos != 0) { - auto* extensionBuffer = new char[5]; - snprintf(&extensionBuffer[0], 5, ".z%02u", number_disk + 1); - diskFilename.replace(pos, 4, extensionBuffer); + const size_t bufferSize = 5; + char extensionBuffer[bufferSize]; + snprintf(&extensionBuffer[0], bufferSize, ".z%02u", number_disk + 1); + diskFilename.replace(pos, std::min((size_t)4, zipFileInfo->zipFileName.size() - pos), extensionBuffer); delete[] extensionBuffer; return ZipFile_open_file_func(opaque, diskFilename.c_str(), mode); }