Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3330)

Unified Diff: blimp/net/compressed_packet_writer.cc

Issue 1882043003: Blimp: add padding for zlib framing to buffer preallocation calculations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use RandBytesAsString() in unit tests. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « blimp/net/compressed_packet_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/net/compressed_packet_writer.cc
diff --git a/blimp/net/compressed_packet_writer.cc b/blimp/net/compressed_packet_writer.cc
index 3fe885611fb04092d01fe361e4362c56b81543a6..1bff4d9bc1266f6c052f0ee5d8e0540572f71c21 100644
--- a/blimp/net/compressed_packet_writer.cc
+++ b/blimp/net/compressed_packet_writer.cc
@@ -20,6 +20,10 @@ namespace {
// compression. (See zconf.h for details on memLevel semantics.)
const int kZlibMemoryLevel = 9;
+// Byte count of the zlib end-of-block marker (0x00, 0x00, 0xFF, 0xFF).
+// Used for buffer preallocation.
+const size_t kZlibBlockMarkerSize = 4;
+
} // namespace
CompressedPacketWriter::CompressedPacketWriter(
@@ -88,8 +92,11 @@ int CompressedPacketWriter::Compress(
const scoped_refptr<net::GrowableIOBuffer>& dest_buf) {
DCHECK_EQ(0, dest_buf->offset());
+ // Preallocate a buffer that's large enough to fit the compressed contents of
+ // src_buf, plus some overhead for zlib.
const int zlib_output_ubound =
- deflateBound(&zlib_stream_, src_buf->BytesRemaining());
+ deflateBound(&zlib_stream_, src_buf->BytesRemaining()) +
+ kZlibBlockMarkerSize;
if (dest_buf->capacity() < zlib_output_ubound) {
dest_buf->SetCapacity(zlib_output_ubound);
}
« no previous file with comments | « blimp/net/compressed_packet_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698