Skip to content

Commit f0016e3

Browse files
committed
refactor decompression logic to use output buffer size (not capacity) + 2x output size on LIBDEFLATE_INSUFFICIENT_SPACE + removed LIBDEFLATE_SHORT_OUTPUT case as we're always passing non NULL actual_size [publish binary]
1 parent b39a441 commit f0016e3

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

src/deflate.hpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,31 +141,25 @@ class Decompressor
141141
size,
142142
const_cast<char*>(output.data()),
143143
output.size(), &actual_size);
144-
if (result != LIBDEFLATE_INSUFFICIENT_SPACE)
144+
if (result == LIBDEFLATE_SUCCESS)
145145
{
146+
output.resize(actual_size);
146147
break;
147148
}
148-
if (output.size() == max_)
149+
else if (result == LIBDEFLATE_INSUFFICIENT_SPACE)
149150
{
150-
throw std::runtime_error("request to resize output buffer can't exceed maximum limit");
151+
if (output.size() == max_)
152+
{
153+
throw std::runtime_error("request to resize output buffer can't exceed maximum limit");
154+
}
155+
std::size_t new_size = std::min(output.size() << 1, max_);
156+
output.resize(new_size);
157+
}
158+
else //LIBDEFLATE_BAD_DATA
159+
{
160+
throw std::runtime_error("bad data: did not succeed");
151161
}
152-
std::size_t new_size = std::min((output.capacity() << 1) - output.size(), max_);
153-
output.resize(new_size);
154-
}
155-
156-
if (result == LIBDEFLATE_SHORT_OUTPUT)
157-
{
158-
throw std::runtime_error("short output: did not succeed");
159-
}
160-
else if (result == LIBDEFLATE_BAD_DATA)
161-
{
162-
throw std::runtime_error("bad data: did not succeed");
163-
}
164-
else if (result != LIBDEFLATE_SUCCESS)
165-
{
166-
throw std::runtime_error("did not succeed");
167162
}
168-
output.resize(actual_size);
169163
}
170164
};
171165

src/vtcomposite.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
namespace vtile {
55

6-
Napi::Value composite(const Napi::CallbackInfo& info);
6+
Napi::Value composite(Napi::CallbackInfo const& info);
77

88
} // namespace vtile

0 commit comments

Comments
 (0)