Skip to content

Commit

Permalink
Count current bytes when backing up the stream
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatcam committed Mar 26, 2020
1 parent 377b17c commit d6b988c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ripple/basics/CompressionAlgorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit d6b988c

Please sign in to comment.