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

Side by Side Diff: net/spdy/hpack/hpack_input_stream.cc

Issue 2026593002: Remove limit on individual hpack string literals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused include. Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « net/spdy/hpack/hpack_input_stream.h ('k') | net/spdy/hpack/hpack_input_stream_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/spdy/hpack/hpack_input_stream.h" 5 #include "net/spdy/hpack/hpack_input_stream.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "net/spdy/hpack/hpack_huffman_decoder.h" 10 #include "net/spdy/hpack/hpack_huffman_decoder.h"
11 #include "net/spdy/spdy_bug_tracker.h" 11 #include "net/spdy/spdy_bug_tracker.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 using base::StringPiece; 15 using base::StringPiece;
16 using std::string; 16 using std::string;
17 17
18 HpackInputStream::HpackInputStream(uint32_t max_string_literal_size, 18 HpackInputStream::HpackInputStream(StringPiece buffer)
19 StringPiece buffer) 19 : buffer_(buffer),
20 : max_string_literal_size_(max_string_literal_size),
21 buffer_(buffer),
22 bit_offset_(0), 20 bit_offset_(0),
23 parsed_bytes_(0), 21 parsed_bytes_(0),
24 parsed_bytes_current_(0), 22 parsed_bytes_current_(0),
25 need_more_data_(false) {} 23 need_more_data_(false) {}
26 24
27 HpackInputStream::~HpackInputStream() {} 25 HpackInputStream::~HpackInputStream() {}
28 26
29 bool HpackInputStream::HasMoreData() const { 27 bool HpackInputStream::HasMoreData() const {
30 return !buffer_.empty(); 28 return !buffer_.empty();
31 } 29 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 118
121 return !has_more; 119 return !has_more;
122 } 120 }
123 121
124 bool HpackInputStream::DecodeNextIdentityString(StringPiece* str) { 122 bool HpackInputStream::DecodeNextIdentityString(StringPiece* str) {
125 uint32_t size = 0; 123 uint32_t size = 0;
126 if (!DecodeNextUint32(&size)) { 124 if (!DecodeNextUint32(&size)) {
127 return false; 125 return false;
128 } 126 }
129 127
130 if (size > max_string_literal_size_) {
131 return false;
132 }
133
134 if (size > buffer_.size()) { 128 if (size > buffer_.size()) {
135 need_more_data_ = true; 129 need_more_data_ = true;
136 return false; 130 return false;
137 } 131 }
138 132
139 *str = StringPiece(buffer_.data(), size); 133 *str = StringPiece(buffer_.data(), size);
140 buffer_.remove_prefix(size); 134 buffer_.remove_prefix(size);
141 parsed_bytes_current_ += size; 135 parsed_bytes_current_ += size;
142 return true; 136 return true;
143 } 137 }
144 138
145 bool HpackInputStream::DecodeNextHuffmanString(string* str) { 139 bool HpackInputStream::DecodeNextHuffmanString(string* str) {
146 uint32_t encoded_size = 0; 140 uint32_t encoded_size = 0;
147 if (!DecodeNextUint32(&encoded_size)) { 141 if (!DecodeNextUint32(&encoded_size)) {
148 if (!need_more_data_) { 142 if (!need_more_data_) {
149 DVLOG(1) << "HpackInputStream::DecodeNextHuffmanString " 143 DVLOG(1) << "HpackInputStream::DecodeNextHuffmanString "
150 << "unable to decode size"; 144 << "unable to decode size";
151 } 145 }
152 return false; 146 return false;
153 } 147 }
154 148
155 if (encoded_size > buffer_.size()) { 149 if (encoded_size > buffer_.size()) {
156 need_more_data_ = true; 150 need_more_data_ = true;
157 DVLOG(1) << "HpackInputStream::DecodeNextHuffmanString " << encoded_size 151 DVLOG(1) << "HpackInputStream::DecodeNextHuffmanString " << encoded_size
158 << " > " << buffer_.size(); 152 << " > " << buffer_.size();
159 return false; 153 return false;
160 } 154 }
161 155
162 HpackInputStream bounded_reader(max_string_literal_size_, 156 HpackInputStream bounded_reader(StringPiece(buffer_.data(), encoded_size));
163 StringPiece(buffer_.data(), encoded_size));
164 buffer_.remove_prefix(encoded_size); 157 buffer_.remove_prefix(encoded_size);
165 parsed_bytes_current_ += encoded_size; 158 parsed_bytes_current_ += encoded_size;
166 159
167 // DecodeString will not append more than |max_string_literal_size_| chars 160 return HpackHuffmanDecoder::DecodeString(&bounded_reader, str);
168 // to |str|.
169 return HpackHuffmanDecoder::DecodeString(&bounded_reader,
170 max_string_literal_size_, str);
171 } 161 }
172 162
173 bool HpackInputStream::PeekBits(size_t* peeked_count, uint32_t* out) const { 163 bool HpackInputStream::PeekBits(size_t* peeked_count, uint32_t* out) const {
174 size_t byte_offset = (bit_offset_ + *peeked_count) / 8; 164 size_t byte_offset = (bit_offset_ + *peeked_count) / 8;
175 size_t bit_offset = (bit_offset_ + *peeked_count) % 8; 165 size_t bit_offset = (bit_offset_ + *peeked_count) % 8;
176 166
177 if (*peeked_count >= 32 || byte_offset >= buffer_.size()) { 167 if (*peeked_count >= 32 || byte_offset >= buffer_.size()) {
178 return false; 168 return false;
179 } 169 }
180 // We'll read the minimum of the current byte remainder, 170 // We'll read the minimum of the current byte remainder,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 243
254 bool HpackInputStream::NeedMoreData() const { 244 bool HpackInputStream::NeedMoreData() const {
255 return need_more_data_; 245 return need_more_data_;
256 } 246 }
257 247
258 void HpackInputStream::MarkCurrentPosition() { 248 void HpackInputStream::MarkCurrentPosition() {
259 parsed_bytes_ = parsed_bytes_current_; 249 parsed_bytes_ = parsed_bytes_current_;
260 } 250 }
261 251
262 } // namespace net 252 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/hpack/hpack_input_stream.h ('k') | net/spdy/hpack/hpack_input_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698