Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions snappy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ inline uint16_t* TableEntry8ByteMatch(uint16_t* table, uint64_t bytes,
} // namespace

size_t MaxCompressedLength(size_t source_bytes) {
// Avoid integer overflow that could cause undersized buffer allocations.
// Return std::numeric_limits<size_t>::max() to force a controlled allocation failure.
if (source_bytes > (std::numeric_limits<size_t>::max() - 32) / 7 * 6) {
return std::numeric_limits<size_t>::max();
}
// Compressed data can be defined as:
// compressed := item* literal*
// item := literal* copy
Expand Down