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");