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

Side by Side Diff: net/http/http_chunked_decoder.cc

Issue 2170133004: HttpChunkedDecoder: Support chunks longer than 2^31-1 bytes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Speed up, beef up tests Created 4 years, 4 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/http/http_chunked_decoder.h ('k') | net/http/http_chunked_decoder_unittest.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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Derived from: 5 // Derived from:
6 // mozilla/netwerk/protocol/http/src/nsHttpChunkedDecoder.cpp 6 // mozilla/netwerk/protocol/http/src/nsHttpChunkedDecoder.cpp
7 // The license block is: 7 // The license block is:
8 /* ***** BEGIN LICENSE BLOCK ***** 8 /* ***** BEGIN LICENSE BLOCK *****
9 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 9 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
10 * 10 *
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 chunk_terminator_remaining_(false), 63 chunk_terminator_remaining_(false),
64 reached_last_chunk_(false), 64 reached_last_chunk_(false),
65 reached_eof_(false), 65 reached_eof_(false),
66 bytes_after_eof_(0) { 66 bytes_after_eof_(0) {
67 } 67 }
68 68
69 int HttpChunkedDecoder::FilterBuf(char* buf, int buf_len) { 69 int HttpChunkedDecoder::FilterBuf(char* buf, int buf_len) {
70 int result = 0; 70 int result = 0;
71 71
72 while (buf_len) { 72 while (buf_len) {
73 if (chunk_remaining_) { 73 if (chunk_remaining_) {
eroman 2016/07/25 18:11:38 side-comment: These sort of "if" statements on sig
mmenke 2016/07/25 18:23:35 I completely agree with you. I've gone ahead and
74 int num = std::min(chunk_remaining_, buf_len); 74 // Since |chunk_remaining_| is positive and |buf_len| an int, the minimum
eroman 2016/07/25 18:11:38 See comment above (hard to reason about at this li
75 // of the two must be an int.
76 int num = static_cast<int>(
77 std::min(chunk_remaining_, static_cast<int64_t>(buf_len)));
75 78
76 buf_len -= num; 79 buf_len -= num;
77 chunk_remaining_ -= num; 80 chunk_remaining_ -= num;
78 81
79 result += num; 82 result += num;
80 buf += num; 83 buf += num;
81 84
82 // After each chunk's data there should be a CRLF 85 // After each chunk's data there should be a CRLF.
83 if (!chunk_remaining_) 86 if (!chunk_remaining_)
84 chunk_terminator_remaining_ = true; 87 chunk_terminator_remaining_ = true;
85 continue; 88 continue;
86 } else if (reached_eof_) { 89 } else if (reached_eof_) {
87 bytes_after_eof_ += buf_len; 90 bytes_after_eof_ += buf_len;
88 break; // Done! 91 break; // Done!
89 } 92 }
90 93
91 int bytes_consumed = ScanForChunkRemaining(buf, buf_len); 94 int bytes_consumed = ScanForChunkRemaining(buf, buf_len);
92 if (bytes_consumed < 0) 95 if (bytes_consumed < 0)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // RFC 7230: ^\X+$ 185 // RFC 7230: ^\X+$
183 // IE7: ^\X+[^\X]*$ 186 // IE7: ^\X+[^\X]*$
184 // Safari 3.1: ^[\t\r ]*\X+[\t ]*$ 187 // Safari 3.1: ^[\t\r ]*\X+[\t ]*$
185 // Firefox 3: ^[\t\f\v\r ]*[+]?(0x)?\X+[^\X]*$ 188 // Firefox 3: ^[\t\f\v\r ]*[+]?(0x)?\X+[^\X]*$
186 // Opera 9.51: ^[\t\f\v ]*[+]?(0x)?\X+[^\X]*$ 189 // Opera 9.51: ^[\t\f\v ]*[+]?(0x)?\X+[^\X]*$
187 // 190 //
188 // Our strategy is to be as strict as possible, while not breaking 191 // Our strategy is to be as strict as possible, while not breaking
189 // known sites. 192 // known sites.
190 // 193 //
191 // Us: ^\X+[ ]*$ 194 // Us: ^\X+[ ]*$
192 bool HttpChunkedDecoder::ParseChunkSize(const char* start, int len, int* out) { 195 bool HttpChunkedDecoder::ParseChunkSize(const char* start,
196 int len,
197 int64_t* out) {
193 DCHECK_GE(len, 0); 198 DCHECK_GE(len, 0);
194 199
195 // Strip trailing spaces 200 // Strip trailing spaces
196 while (len && start[len - 1] == ' ') 201 while (len && start[len - 1] == ' ')
197 len--; 202 len--;
198 203
199 // Be more restrictive than HexStringToInt; 204 // Be more restrictive than HexStringToInt64;
200 // don't allow inputs with leading "-", "+", "0x", "0X" 205 // don't allow inputs with leading "-", "+", "0x", "0X"
201 base::StringPiece chunk_size(start, len); 206 base::StringPiece chunk_size(start, len);
202 if (chunk_size.find_first_not_of("0123456789abcdefABCDEF") 207 if (chunk_size.find_first_not_of("0123456789abcdefABCDEF")
mmenke 2016/07/25 15:36:01 Could consider adding this to net/base/parse_numbe
203 != base::StringPiece::npos) { 208 != base::StringPiece::npos) {
204 return false; 209 return false;
205 } 210 }
206 211
207 int parsed_number; 212 int64_t parsed_number;
208 bool ok = base::HexStringToInt(chunk_size, &parsed_number); 213 bool ok = base::HexStringToInt64(chunk_size, &parsed_number);
209 if (ok && parsed_number >= 0) { 214 if (ok && parsed_number >= 0) {
210 *out = parsed_number; 215 *out = parsed_number;
211 return true; 216 return true;
212 } 217 }
213 return false; 218 return false;
214 } 219 }
215 220
216 } // namespace net 221 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_chunked_decoder.h ('k') | net/http/http_chunked_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698