Implement overflow check in MaxCompressedLength function
Add overflow check for buffer allocation in MaxCompressedLength
diff --git a/snappy.cc b/snappy.cc
index ab61792..46d870c 100644
--- a/snappy.cc
+++ b/snappy.cc
@@ -194,6 +194,11 @@
} // 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) {
+ return SIZE_MAX;
+ }
// Compressed data can be defined as:
// compressed := item* literal*
// item := literal* copy