Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue: #20182 #20192

Merged
merged 1 commit into from
Oct 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions cocos/base/ZipUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#else // from our embedded sources
#include "unzip.h"
#endif
#include "ioapi_mem.h"
#include <memory>

#include <zlib.h>
#include <assert.h>
Expand Down Expand Up @@ -509,6 +511,7 @@ class ZipFilePrivate
{
public:
unzFile zipFile;
std::unique_ptr<ourmemory_s> memfs;

// std::unordered_map is faster if available on the platform
typedef std::unordered_map<std::string, struct ZipEntryInfo> FileListContainer;
Expand Down Expand Up @@ -739,10 +742,17 @@ int ZipFile::getCurrentFileInfo(std::string *filename, unz_file_info *info)
bool ZipFile::initWithBuffer(const void *buffer, uLong size)
{
if (!buffer || size == 0) return false;

zlib_filefunc_def memory_file = { 0 };

_data->zipFile = unzOpenBuffer(buffer, size);
if (!_data->zipFile) return false;
std::unique_ptr<ourmemory_t> memfs(new(std::nothrow) ourmemory_t{ (char*)const_cast<void*>(buffer), static_cast<uint32_t>(size), 0, 0, 0 });
if (!memfs) return false;
fill_memory_filefunc(&memory_file, memfs.get());

_data->zipFile = unzOpen2(nullptr, &memory_file);
if (!_data->zipFile) return false;
_data->memfs = std::move(memfs);

setFilter(emptyFilename);
return true;
}
Expand Down