Skip to content
Open
Changes from 1 commit
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 SIZE_MAX to force a controlled allocation failure.
if (source_bytes > (SIZE_MAX - 32) / 7 * 6) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Can you use std::numeric_limits<size_t>::max() ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I initially used SIZE_MAX because I didn't notice was included transitively through snappy-stubs-internal.h. Now that I see it's available, I'll update to std::numeric_limits<size_t>::max(). Thanks for the suggestion.

return SIZE_MAX;
}
// Compressed data can be defined as:
// compressed := item* literal*
// item := literal* copy
Expand Down
Loading