Skip to content
Open
Changes from all 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
6 changes: 6 additions & 0 deletions snappy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <limits>
#include <memory>
#include <string>
#include <utility>
Expand Down Expand Up @@ -194,6 +195,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
Loading