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

Unified Diff: blimp/net/stream_packet_reader.cc

Issue 1825263003: Blimp: add packet-level DEFLATE compression using zlib. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Wez feedback. Created 4 years, 9 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
Index: blimp/net/stream_packet_reader.cc
diff --git a/blimp/net/stream_packet_reader.cc b/blimp/net/stream_packet_reader.cc
index da65ad99fa07beb8077005ef0b8b28a228ba5bfe..8e675b32c8b3bfe511d07c84bb7fdfd9d8e85c52 100644
--- a/blimp/net/stream_packet_reader.cc
+++ b/blimp/net/stream_packet_reader.cc
@@ -47,7 +47,9 @@ void StreamPacketReader::ReadPacket(
const scoped_refptr<net::GrowableIOBuffer>& buf,
const net::CompletionCallback& callback) {
DCHECK_EQ(ReadState::IDLE, read_state_);
- DCHECK_GT(buf->capacity(), 0);
+ if (static_cast<size_t>(buf->capacity()) < kPacketHeaderSizeBytes) {
+ buf->SetCapacity(kPacketHeaderSizeBytes);
+ }
header_buffer_->set_offset(0);
payload_buffer_ = buf;
@@ -114,11 +116,13 @@ int StreamPacketReader::DoReadHeader(int result) {
// Finished reading the header. Parse the size and prepare for payload read.
payload_size_ = base::NetToHost32(
*reinterpret_cast<uint32_t*>(header_buffer_->StartOfBuffer()));
- if (payload_size_ > static_cast<size_t>(payload_buffer_->capacity()) ||
- payload_size_ == 0) {
+ if (payload_size_ == 0 || payload_size_ > kMaxPacketPayloadSizeBytes) {
DLOG(ERROR) << "Illegal payload size: " << payload_size_;
return net::ERR_INVALID_RESPONSE;
}
+ if (static_cast<size_t>(payload_buffer_->capacity()) < payload_size_) {
+ payload_buffer_->SetCapacity(payload_size_);
+ }
read_state_ = ReadState::PAYLOAD;
return net::OK;
}

Powered by Google App Engine
This is Rietveld 408576698