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.
This commit is contained in:
sbrednikhin 2017-04-28 07:38:23 +02:00 committed by minggo
parent e45cb88ead
commit 07bb0b2393
1 changed files with 2 additions and 2 deletions

View File

@ -414,9 +414,9 @@ namespace cocos2d { namespace network {
std::string errorString;
const int64_t buflen = [wrapper totalBytesReceived];
char buf[buflen];
std::vector<unsigned char> data((size_t)buflen);
char* buf = (char*)data.data();
[wrapper transferDataToBuffer:buf lengthOfBuffer:buflen];
std::vector<unsigned char> data(buf, buf + buflen);
_outer->onTaskFinish(*[wrapper get],
cocos2d::network::DownloadTask::ERROR_NO_ERROR,