Skip to content

Commit

Permalink
Clear trailing bytes in StreamVByte to ensure bit-exact output
Browse files Browse the repository at this point in the history
StreamVByte codec rounds up output size to multiple of 4 bytes. As a result, up to 3 trailing bytes could be uninitialized memory passed to the encodeArray function. To ensure bitexact output, these padding bytes should be cleared.
  • Loading branch information
pps83 committed Jun 9, 2024
1 parent bc37505 commit 34ee4bb
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions headers/streamvariablebyte.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class StreamVByte : public IntegerCODEC {
count, std::numeric_limits<uint32_t>::max())),
0, 1);
nvalue = static_cast<size_t>(bytesWritten + 3) / 4;
for (size_t i = bytesWritten; i < nvalue*4; ++i)
((uint8_t*)out)[i] = 0;
}

const uint32_t *decodeArray(const uint32_t *in, const size_t /* count */,
Expand Down

0 comments on commit 34ee4bb

Please sign in to comment.