Commit 40d46a81 authored by Ingvar Stepanyan's avatar Ingvar Stepanyan

Fix double-free after move of context

parent e57066ca
...@@ -214,7 +214,7 @@ KJ_TEST("async gzip decompression") { ...@@ -214,7 +214,7 @@ KJ_TEST("async gzip decompression") {
// Decompress using an output stream. // Decompress using an output stream.
{ {
MockAsyncOutputStream rawOutput; MockAsyncOutputStream rawOutput;
auto gzip = GzipAsyncOutputStream::Decompress(rawOutput); GzipAsyncOutputStream gzip(rawOutput, GzipAsyncOutputStream::DECOMPRESS);
auto mid = sizeof(FOOBAR_GZIP) / 2; auto mid = sizeof(FOOBAR_GZIP) / 2;
gzip.write(FOOBAR_GZIP, mid).wait(io.waitScope); gzip.write(FOOBAR_GZIP, mid).wait(io.waitScope);
......
...@@ -142,9 +142,12 @@ size_t GzipInputStream::readImpl( ...@@ -142,9 +142,12 @@ size_t GzipInputStream::readImpl(
// ======================================================================================= // =======================================================================================
GzipOutputStream::GzipOutputStream(OutputStream& inner, kj::Maybe<int> compressionLevel) GzipOutputStream::GzipOutputStream(OutputStream& inner, int compressionLevel)
: inner(inner), ctx(compressionLevel) {} : inner(inner), ctx(compressionLevel) {}
GzipOutputStream::GzipOutputStream(OutputStream& inner, decltype(DECOMPRESS))
: inner(inner), ctx(nullptr) {}
GzipOutputStream::~GzipOutputStream() noexcept(false) { GzipOutputStream::~GzipOutputStream() noexcept(false) {
pump(Z_FINISH); pump(Z_FINISH);
} }
...@@ -228,9 +231,12 @@ Promise<size_t> GzipAsyncInputStream::readImpl( ...@@ -228,9 +231,12 @@ Promise<size_t> GzipAsyncInputStream::readImpl(
// ======================================================================================= // =======================================================================================
GzipAsyncOutputStream::GzipAsyncOutputStream(AsyncOutputStream& inner, kj::Maybe<int> compressionLevel) GzipAsyncOutputStream::GzipAsyncOutputStream(AsyncOutputStream& inner, int compressionLevel)
: inner(inner), ctx(compressionLevel) {} : inner(inner), ctx(compressionLevel) {}
GzipAsyncOutputStream::GzipAsyncOutputStream(AsyncOutputStream& inner, decltype(DECOMPRESS))
: inner(inner), ctx(nullptr) {}
Promise<void> GzipAsyncOutputStream::write(const void* in, size_t size) { Promise<void> GzipAsyncOutputStream::write(const void* in, size_t size) {
ctx.setInput(in, size); ctx.setInput(in, size);
return pump(Z_NO_FLUSH); return pump(Z_NO_FLUSH);
......
...@@ -34,7 +34,6 @@ public: ...@@ -34,7 +34,6 @@ public:
GzipOutputContext(kj::Maybe<int> compressionLevel); GzipOutputContext(kj::Maybe<int> compressionLevel);
~GzipOutputContext() noexcept(false); ~GzipOutputContext() noexcept(false);
KJ_DISALLOW_COPY(GzipOutputContext); KJ_DISALLOW_COPY(GzipOutputContext);
GzipOutputContext(GzipOutputContext&&) = default;
void setInput(const void* in, size_t size); void setInput(const void* in, size_t size);
kj::Tuple<bool, kj::ArrayPtr<const byte>> pumpOnce(int flush); kj::Tuple<bool, kj::ArrayPtr<const byte>> pumpOnce(int flush);
...@@ -69,14 +68,12 @@ private: ...@@ -69,14 +68,12 @@ private:
class GzipOutputStream final: public OutputStream { class GzipOutputStream final: public OutputStream {
public: public:
GzipOutputStream(OutputStream& inner, kj::Maybe<int> compressionLevel = Z_DEFAULT_COMPRESSION); enum { DECOMPRESS };
GzipOutputStream(OutputStream& inner, int compressionLevel = Z_DEFAULT_COMPRESSION);
GzipOutputStream(OutputStream& inner, decltype(DECOMPRESS));
~GzipOutputStream() noexcept(false); ~GzipOutputStream() noexcept(false);
KJ_DISALLOW_COPY(GzipOutputStream); KJ_DISALLOW_COPY(GzipOutputStream);
GzipOutputStream(GzipOutputStream&&) = default;
static inline GzipOutputStream Decompress(OutputStream& inner) {
return GzipOutputStream(inner, nullptr);
}
void write(const void* buffer, size_t size) override; void write(const void* buffer, size_t size) override;
using OutputStream::write; using OutputStream::write;
...@@ -112,13 +109,11 @@ private: ...@@ -112,13 +109,11 @@ private:
class GzipAsyncOutputStream final: public AsyncOutputStream { class GzipAsyncOutputStream final: public AsyncOutputStream {
public: public:
GzipAsyncOutputStream(AsyncOutputStream& inner, kj::Maybe<int> compressionLevel = Z_DEFAULT_COMPRESSION); enum { DECOMPRESS };
KJ_DISALLOW_COPY(GzipAsyncOutputStream);
GzipAsyncOutputStream(GzipAsyncOutputStream&&) = default;
static inline GzipAsyncOutputStream Decompress(AsyncOutputStream& inner) { GzipAsyncOutputStream(AsyncOutputStream& inner, int compressionLevel = Z_DEFAULT_COMPRESSION);
return GzipAsyncOutputStream(inner, nullptr); GzipAsyncOutputStream(AsyncOutputStream& inner, decltype(DECOMPRESS));
} KJ_DISALLOW_COPY(GzipAsyncOutputStream);
Promise<void> write(const void* buffer, size_t size) override; Promise<void> write(const void* buffer, size_t size) override;
Promise<void> write(ArrayPtr<const ArrayPtr<const byte>> pieces) override; Promise<void> write(ArrayPtr<const ArrayPtr<const byte>> pieces) override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment