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

Unified 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: Missed two Created 4 years, 5 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 | « net/http/http_chunked_decoder.h ('k') | net/http/http_chunked_decoder_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_chunked_decoder.cc
diff --git a/net/http/http_chunked_decoder.cc b/net/http/http_chunked_decoder.cc
index 7aa4a965cd707cc705a693863bb75a6f26ef91b1..fab94342adb14e28b857594db1b66d41793343a8 100644
--- a/net/http/http_chunked_decoder.cc
+++ b/net/http/http_chunked_decoder.cc
@@ -69,9 +69,12 @@ HttpChunkedDecoder::HttpChunkedDecoder()
int HttpChunkedDecoder::FilterBuf(char* buf, int buf_len) {
int result = 0;
- while (buf_len) {
- if (chunk_remaining_) {
- int num = std::min(chunk_remaining_, buf_len);
+ while (buf_len > 0) {
+ if (chunk_remaining_ > 0) {
+ // Since |chunk_remaining_| is positive and |buf_len| an int, the minimum
+ // of the two must be an int.
+ int num = static_cast<int>(
+ std::min(chunk_remaining_, static_cast<int64_t>(buf_len)));
buf_len -= num;
chunk_remaining_ -= num;
@@ -79,8 +82,8 @@ int HttpChunkedDecoder::FilterBuf(char* buf, int buf_len) {
result += num;
buf += num;
- // After each chunk's data there should be a CRLF
- if (!chunk_remaining_)
+ // After each chunk's data there should be a CRLF.
+ if (chunk_remaining_ == 0)
chunk_terminator_remaining_ = true;
continue;
} else if (reached_eof_) {
@@ -93,7 +96,7 @@ int HttpChunkedDecoder::FilterBuf(char* buf, int buf_len) {
return bytes_consumed; // Error
buf_len -= bytes_consumed;
- if (buf_len)
+ if (buf_len > 0)
memmove(buf, buf + bytes_consumed, buf_len);
}
@@ -121,17 +124,17 @@ int HttpChunkedDecoder::ScanForChunkRemaining(const char* buf, int buf_len) {
}
if (reached_last_chunk_) {
- if (buf_len)
+ if (buf_len > 0)
DVLOG(1) << "ignoring http trailer";
else
reached_eof_ = true;
} else if (chunk_terminator_remaining_) {
- if (buf_len) {
+ if (buf_len > 0) {
DLOG(ERROR) << "chunk data not terminated properly";
return ERR_INVALID_CHUNKED_ENCODING;
}
chunk_terminator_remaining_ = false;
- } else if (buf_len) {
+ } else if (buf_len > 0) {
// Ignore any chunk-extensions.
size_t index_of_semicolon = base::StringPiece(buf, buf_len).find(';');
if (index_of_semicolon != base::StringPiece::npos)
@@ -189,14 +192,16 @@ int HttpChunkedDecoder::ScanForChunkRemaining(const char* buf, int buf_len) {
// known sites.
//
// Us: ^\X+[ ]*$
-bool HttpChunkedDecoder::ParseChunkSize(const char* start, int len, int* out) {
+bool HttpChunkedDecoder::ParseChunkSize(const char* start,
+ int len,
+ int64_t* out) {
DCHECK_GE(len, 0);
// Strip trailing spaces
- while (len && start[len - 1] == ' ')
+ while (len > 0 && start[len - 1] == ' ')
len--;
- // Be more restrictive than HexStringToInt;
+ // Be more restrictive than HexStringToInt64;
// don't allow inputs with leading "-", "+", "0x", "0X"
base::StringPiece chunk_size(start, len);
if (chunk_size.find_first_not_of("0123456789abcdefABCDEF")
@@ -204,8 +209,8 @@ bool HttpChunkedDecoder::ParseChunkSize(const char* start, int len, int* out) {
return false;
}
- int parsed_number;
- bool ok = base::HexStringToInt(chunk_size, &parsed_number);
+ int64_t parsed_number;
+ bool ok = base::HexStringToInt64(chunk_size, &parsed_number);
if (ok && parsed_number >= 0) {
*out = parsed_number;
return true;
« 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