From 07bb0b2393b9ce9986c6db3fd24e52aca6ae3904 Mon Sep 17 00:00:00 2001 From: sbrednikhin Date: Fri, 28 Apr 2017 07:38:23 +0200 Subject: [PATCH] Avoid crash on large file download. (#17735) Downloading large file to memory could cause stack overflow and crash, because old code created buffer `char buf[buflen];` in stack. New code creates buffer in heap. --- cocos/network/CCDownloader-apple.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/network/CCDownloader-apple.mm b/cocos/network/CCDownloader-apple.mm index 99fcfa3745..8d67db6d96 100644 --- a/cocos/network/CCDownloader-apple.mm +++ b/cocos/network/CCDownloader-apple.mm @@ -414,9 +414,9 @@ namespace cocos2d { namespace network { std::string errorString; const int64_t buflen = [wrapper totalBytesReceived]; - char buf[buflen]; + std::vector data((size_t)buflen); + char* buf = (char*)data.data(); [wrapper transferDataToBuffer:buf lengthOfBuffer:buflen]; - std::vector data(buf, buf + buflen); _outer->onTaskFinish(*[wrapper get], cocos2d::network::DownloadTask::ERROR_NO_ERROR,