From eb3a651bab4059604178616c5b04ce30fbcf77a2 Mon Sep 17 00:00:00 2001 From: alesapin Date: Thu, 23 Sep 2021 16:49:48 +0300 Subject: [PATCH] Fix bug found on review --- src/IO/ZstdDeflatingAppendableWriteBuffer.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/IO/ZstdDeflatingAppendableWriteBuffer.cpp b/src/IO/ZstdDeflatingAppendableWriteBuffer.cpp index acf818e64d7..536fbf35113 100644 --- a/src/IO/ZstdDeflatingAppendableWriteBuffer.cpp +++ b/src/IO/ZstdDeflatingAppendableWriteBuffer.cpp @@ -151,10 +151,14 @@ void ZstdDeflatingAppendableWriteBuffer::finishImpl() void ZstdDeflatingAppendableWriteBuffer::addEmptyBlock() { /// HACK: https://github.com/facebook/zstd/issues/2090#issuecomment-620158967 - out.nextIfAtEnd(); static const char empty_block[3] = {0x01, 0x00, 0x00}; + + if (out.buffer().size() - out.offset() < sizeof(empty_block)) + out.next(); + std::memcpy(out.buffer().begin() + out.offset(), empty_block, sizeof(empty_block)); - out.position() = out.buffer().begin() + sizeof(empty_block); + + out.position() = out.buffer().begin() + out.offset() + sizeof(empty_block); } }