Chromium Code Reviews| Index: net/http/http_util.cc |
| diff --git a/net/http/http_util.cc b/net/http/http_util.cc |
| index 24066ef94c5e6770ef84ae0fe1d0deef1a604786..e8f9c4ebd6e7b14a9ab06681cb4d6b6e7c365500 100644 |
| --- a/net/http/http_util.cc |
| +++ b/net/http/http_util.cc |
| @@ -288,53 +288,31 @@ bool HttpUtil::ParseContentRangeHeader(base::StringPiece content_range_spec, |
| return false; |
| } |
| - size_t slash_position = content_range_spec.find('/', space_position + 1); |
| + size_t minus_position = content_range_spec.find('-', space_position + 1); |
| + if (minus_position == base::StringPiece::npos) |
| + return false; |
| + size_t slash_position = content_range_spec.find('/', minus_position + 1); |
| if (slash_position == base::StringPiece::npos) |
| return false; |
| - // Obtain the part behind the space and before slash. |
| - base::StringPiece byte_range_resp_spec = TrimLWS(content_range_spec.substr( |
| - space_position + 1, slash_position - (space_position + 1))); |
| - |
| - if (byte_range_resp_spec != "*") { |
| - size_t minus_position = byte_range_resp_spec.find('-'); |
| - if (minus_position == base::StringPiece::npos) |
| - return false; |
| - |
| - // Obtain first-byte-pos and last-byte-pos. |
| - if (!base::StringToInt64( |
| - TrimLWS(byte_range_resp_spec.substr(0, minus_position)), |
| - first_byte_position) || |
| - !base::StringToInt64( |
| - TrimLWS(byte_range_resp_spec.substr(minus_position + 1)), |
| - last_byte_position)) { |
| - *first_byte_position = *last_byte_position = -1; |
| - return false; |
| - } |
| - if (*first_byte_position < 0 || *last_byte_position < 0 || |
| - *first_byte_position > *last_byte_position) |
| - return false; |
| - } |
| - |
| - // Parse the instance-length part. |
| - base::StringPiece instance_length_spec = |
| - TrimLWS(content_range_spec.substr(slash_position + 1)); |
| - |
| - if (base::StartsWith(instance_length_spec, "*", |
| - base::CompareCase::SENSITIVE)) { |
| - return false; |
| - } else if (!base::StringToInt64(instance_length_spec, instance_length)) { |
| - *instance_length = -1; |
| - return false; |
| + if (base::StringToInt64( |
| + TrimLWS(content_range_spec.substr( |
| + space_position + 1, minus_position - (space_position + 1))), |
| + first_byte_position) && |
| + *first_byte_position >= 0 && |
| + base::StringToInt64( |
| + TrimLWS(content_range_spec.substr( |
| + minus_position + 1, slash_position - (minus_position + 1))), |
| + last_byte_position) && |
| + *last_byte_position >= *first_byte_position && |
| + base::StringToInt64( |
| + TrimLWS(content_range_spec.substr(slash_position + 1)), |
| + instance_length) && |
| + *instance_length > *last_byte_position) { |
| + return true; |
| } |
|
mmenke
2016/12/06 19:18:06
nit: Suggest a blank line here.
|
| - |
| - // We have all the values; let's verify that they make sense for a 206 |
| - // response. |
| - if (*first_byte_position < 0 || *last_byte_position < 0 || |
| - *instance_length < 0 || *instance_length - 1 < *last_byte_position) |
| - return false; |
| - |
| - return true; |
| + *first_byte_position = *last_byte_position = *instance_length = -1; |
| + return false; |
| } |
| // static |