From d6b988cec5c58e7aba03a57af1e092d7dd23fcd5 Mon Sep 17 00:00:00 2001 From: Gregory Tsipenyuk Date: Wed, 25 Mar 2020 07:14:03 -0400 Subject: [PATCH] Count current bytes when backing up the stream --- src/ripple/basics/CompressionAlgorithms.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ripple/basics/CompressionAlgorithms.h b/src/ripple/basics/CompressionAlgorithms.h index eb5e40b4b68..3cd67c753d8 100644 --- a/src/ripple/basics/CompressionAlgorithms.h +++ b/src/ripple/basics/CompressionAlgorithms.h @@ -106,6 +106,7 @@ lz4Decompress(InputStream& in, std::size_t inSize, std::uint8_t const* chunk = nullptr; int chunkSize = 0; int copiedInSize = 0; + auto const currentBytes = in.ByteCount(); // Use the first chunk if it is >= inSize bytes of the compressed message. // Otherwise copy inSize bytes of chunks into compressed buffer and @@ -136,8 +137,8 @@ lz4Decompress(InputStream& in, std::size_t inSize, } // Put back unused bytes - if (in.ByteCount() > copiedInSize) - in.BackUp(in.ByteCount() - copiedInSize); + if (in.ByteCount() > (currentBytes + copiedInSize)) + in.BackUp(in.ByteCount() - currentBytes - copiedInSize); if ((copiedInSize == 0 && chunkSize < inSize) || (copiedInSize > 0 && copiedInSize != inSize)) doThrow("lz4 decompress: insufficient input size");