diff options
-rw-r--r-- | net/http/http_chunked_decoder.cc | 12 | ||||
-rw-r--r-- | net/http/http_chunked_decoder.h | 6 |
2 files changed, 12 insertions, 6 deletions
diff --git a/net/http/http_chunked_decoder.cc b/net/http/http_chunked_decoder.cc index 6ecdcad..71f7554 100644 --- a/net/http/http_chunked_decoder.cc +++ b/net/http/http_chunked_decoder.cc @@ -125,8 +125,7 @@ int HttpChunkedDecoder::ScanForChunkRemaining(const char* buf, int buf_len) { if (index_of_semicolon != StringPiece::npos) buf_len = static_cast<int>(index_of_semicolon); - if (!ParseChunkSize(buf, buf_len, &chunk_remaining_) || - chunk_remaining_ < 0) { + if (!ParseChunkSize(buf, buf_len, &chunk_remaining_)) { DLOG(ERROR) << "Failed parsing HEX from: " << std::string(buf, buf_len); return ERR_INVALID_CHUNKED_ENCODING; @@ -185,7 +184,14 @@ bool HttpChunkedDecoder::ParseChunkSize(const char* start, int len, int* out) { if (StringPiece(start, len).find_first_not_of("0123456789abcdefABCDEF")!= StringPiece::npos) return false; - return HexStringToInt(std::string(start, len), out); + + int parsed_number; + bool ok = HexStringToInt(std::string(start, len), &parsed_number); + if (ok && parsed_number >= 0) { + *out = parsed_number; + return true; + } + return false; } } // namespace net diff --git a/net/http/http_chunked_decoder.h b/net/http/http_chunked_decoder.h index 1eb3ea0..f87ae5e 100644 --- a/net/http/http_chunked_decoder.h +++ b/net/http/http_chunked_decoder.h @@ -84,14 +84,14 @@ class HttpChunkedDecoder { int FilterBuf(char* buf, int buf_len); private: - // Scan |buf| for the next chunk delimiter. This method returns the number + // Scans |buf| for the next chunk delimiter. This method returns the number // of bytes consumed from |buf|. If found, |chunk_remaining_| holds the // value for the next chunk size. int ScanForChunkRemaining(const char* buf, int buf_len); - // Convert string |start| of length |len| to a numeric value. + // Converts string |start| of length |len| to a numeric value. // |start| is a string of type "chunk-size" (hex string). - // If the conversion succeeds, return true and place the result in |out|. + // If the conversion succeeds, returns true and places the result in |out|. static bool ParseChunkSize(const char* start, int len, int* out); // Indicates the number of bytes remaining for the current chunk. |