mirror of
https://github.com/minetest/minetestmapper.git
synced 2025-04-19 11:00:29 +02:00
Fix broken buffer handling in ZlibDecompressor
40a5e16e21ba9a0663fc93919291c1bf0e5c2e3a added the broken reserve() call and only by chance did 0a56b18cfbb583649bdbc7f0a379df5d63ea2880 not break it further because I forgot to remove the unconditional resize(). I should read my own code changes more often.
This commit is contained in:
parent
314debe4fb
commit
9367e45e66
@ -48,16 +48,17 @@ void ZlibDecompressor::decompress(ustring &buffer)
|
|||||||
|
|
||||||
strm.next_in = const_cast<unsigned char *>(data);
|
strm.next_in = const_cast<unsigned char *>(data);
|
||||||
strm.avail_in = size;
|
strm.avail_in = size;
|
||||||
|
if (buffer.empty())
|
||||||
buffer.resize(BUFSIZE);
|
buffer.resize(BUFSIZE);
|
||||||
strm.next_out = &buffer[0];
|
strm.next_out = &buffer[0];
|
||||||
strm.avail_out = BUFSIZE;
|
strm.avail_out = buffer.size();
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
do {
|
do {
|
||||||
ret = Z(inflate)(&strm, Z_NO_FLUSH);
|
ret = Z(inflate)(&strm, Z_NO_FLUSH);
|
||||||
if (strm.avail_out == 0) {
|
if (strm.avail_out == 0) {
|
||||||
const auto off = buffer.size();
|
const auto off = buffer.size();
|
||||||
buffer.reserve(off + BUFSIZE);
|
buffer.resize(off + BUFSIZE);
|
||||||
strm.next_out = &buffer[off];
|
strm.next_out = &buffer[off];
|
||||||
strm.avail_out = BUFSIZE;
|
strm.avail_out = BUFSIZE;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ void ZstdDecompressor::decompress(ustring &buffer)
|
|||||||
// output space is extended in chunks of this size
|
// output space is extended in chunks of this size
|
||||||
constexpr size_t BUFSIZE = 8 * 1024;
|
constexpr size_t BUFSIZE = 8 * 1024;
|
||||||
|
|
||||||
|
if (buffer.empty())
|
||||||
buffer.resize(BUFSIZE);
|
buffer.resize(BUFSIZE);
|
||||||
ZSTD_outBuffer outbuf = { &buffer[0], buffer.size(), 0 };
|
ZSTD_outBuffer outbuf = { &buffer[0], buffer.size(), 0 };
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user