summaryrefslogtreecommitdiffstats
path: root/net/http/http_chunked_decoder.cc
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-15 21:06:12 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-15 21:06:12 +0000
commite05294e5feca88329e5d795bc927da82cd97656a (patch)
treecae091cc7166bd3661c88872021f938657c1c699 /net/http/http_chunked_decoder.cc
parenta88d601f7f632a21afe88359d503559fa20d9e40 (diff)
downloadchromium_src-e05294e5feca88329e5d795bc927da82cd97656a.zip
chromium_src-e05294e5feca88329e5d795bc927da82cd97656a.tar.gz
chromium_src-e05294e5feca88329e5d795bc927da82cd97656a.tar.bz2
-Add error code for chunked encoding
-Add unit test for chunk-size > 2GB -Allow trailing space (0x20) -Document how other browsers parse the chunk-size BUG=1326627 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@961 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_chunked_decoder.cc')
-rw-r--r--net/http/http_chunked_decoder.cc33
1 files changed, 29 insertions, 4 deletions
diff --git a/net/http/http_chunked_decoder.cc b/net/http/http_chunked_decoder.cc
index 9c0bbcb..1afe0f2 100644
--- a/net/http/http_chunked_decoder.cc
+++ b/net/http/http_chunked_decoder.cc
@@ -116,7 +116,7 @@ int HttpChunkedDecoder::ScanForChunkRemaining(const char* buf, int buf_len) {
} else if (chunk_terminator_remaining_) {
if (buf_len) {
DLOG(ERROR) << "chunk data not terminated properly";
- return ERR_FAILED;
+ return ERR_BAD_CHUNKED_ENCODING;
}
chunk_terminator_remaining_ = false;
} else if (buf_len) {
@@ -128,14 +128,14 @@ int HttpChunkedDecoder::ScanForChunkRemaining(const char* buf, int buf_len) {
if (!ParseChunkSize(buf, buf_len, &chunk_remaining_)) {
DLOG(ERROR) << "Failed parsing HEX from: " <<
std::string(buf, buf_len);
- return ERR_FAILED;
+ return ERR_BAD_CHUNKED_ENCODING;
}
if (chunk_remaining_ == 0)
reached_last_chunk_ = true;
} else {
DLOG(ERROR) << "missing chunk-size";
- return ERR_FAILED;
+ return ERR_BAD_CHUNKED_ENCODING;
}
line_buf_.clear();
} else {
@@ -151,8 +151,33 @@ int HttpChunkedDecoder::ScanForChunkRemaining(const char* buf, int buf_len) {
return bytes_consumed;
}
-// static
+
+// While the HTTP 1.1 specification defines chunk-size as 1*HEX
+// some sites rely on more lenient parsing.
+// yahoo.com for example, includes trailing spaces (0x20).
+//
+// A comparison of browsers running on WindowsXP shows that
+// they will parse the following inputs (egrep syntax):
+//
+// Let \X be the character class for a hex digit: [0-9a-fA-F]
+//
+// RFC 2616: ^\X+$
+// IE7: ^\X+[^\X]*$
+// Safari 3.1: ^[\t\r ]*\X+[\t ]*$
+// Firefox 3: ^[\t\f\v\r ]*[+]?(0x)?\X+[^\X]*$
+// Opera 9.51: ^[\t\f\v ]*[+]?(0x)?\X+[^\X]*$
+//
+// Our strategy is to be as strict as possible, while not breaking
+// known sites.
+//
+// Chromium: ^\X+[ ]*$
bool HttpChunkedDecoder::ParseChunkSize(const char* start, int len, int* out) {
+ DCHECK(len >= 0);
+
+ // Strip trailing spaces
+ while (len && start[len - 1] == ' ')
+ len--;
+
// Be more restrictive than HexStringToInt;
// don't allow inputs with leading "-", "+", "0x", "0X"
if (StringPiece(start, len).find_first_not_of("0123456789abcdefABCDEF")!=