Skip to content

Commit f28888e

Browse files
authored
fix: smashing stack on Huffman test (#6102)
* fix: reproduce a bug * fix: test updated * fix: test updated * fix: code fixed * fix: review comments
1 parent aa01520 commit f28888e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/core/compact_object.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,10 @@ uint64_t CompactObj::HashCode() const {
861861
DCHECK(mask_bits_.encoding);
862862

863863
if (IsInline()) {
864-
char buf[kInlineLen * 3]; // should suffice for most huffman decodings.
864+
// Buffer must accommodate maximum decompressed size from inline storage
865+
// Highly compressible data can achieve ~8x compression (e.g., repeated character)
866+
// kInlineLen (16 bytes) compressed -> up to 128 bytes decompressed
867+
char buf[kInlineLen * 8];
865868
size_t decoded_len = GetStrEncoding().Decode(string_view{u_.inline_str, taglen_}, buf);
866869
return XXH3_64bits_withSeed(buf, decoded_len, kHashSeed);
867870
}
@@ -1411,7 +1414,8 @@ bool CompactObj::CmpEncoded(string_view sv) const {
14111414
return false;
14121415

14131416
if (IsInline()) {
1414-
constexpr size_t kMaxHuffLen = kInlineLen * 3;
1417+
// Buffer must accommodate maximum decompressed size from inline storage (~8x compression)
1418+
constexpr size_t kMaxHuffLen = kInlineLen * 8;
14151419
if (sz <= kMaxHuffLen) {
14161420
char buf[kMaxHuffLen];
14171421
const auto& decoder = tl.GetHuffmanDecoder(huffman_domain_);

0 commit comments

Comments
 (0)