Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/DataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ DataFilePrivate::DataFilePrivate(const ZipSerialize &z, string filename, string
m_is = std::move(fs);
}
else
m_is = make_unique<stringstream>(r.operator string());
m_is = make_unique<stringstream>(r(MAX_MEM_FILE));
}

DataFilePrivate::~DataFilePrivate() noexcept = default;
Expand Down
10 changes: 8 additions & 2 deletions src/util/ZipSerialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#pragma once

#include "Exports.h"
#include "log.h"

#include <memory>
#include <string>
Expand All @@ -34,14 +35,19 @@ class ZipSerialize
{
public:
struct Read {
static constexpr size_t maxSize = 10UL*1024*1024;
size_t operator ()(void *data, size_t size) const;
template<class T>
constexpr operator T() const
template<class T = std::string>
T operator ()(size_t maxAlloc = maxSize) const
{
if(size > maxAlloc)
THROW("ZIP entry uncompressed size %zu exceeds limit", size);
T t(size, 0);
t.resize(operator ()(t.data(), t.size()));
return t;
}
template<class T>
constexpr operator T() const { return operator()<T>(); }
std::unique_ptr<void, int (*)(void*)> d;
size_t size;
};
Expand Down