Skip to content
Permalink
Browse files

Auto merge of #23036 - gterzian:fix_range_request, r=<try>

Checked arithmetics in cache range request

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #23030 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23036)
<!-- Reviewable:end -->
  • Loading branch information...
bors-servo committed Mar 14, 2019
2 parents 85ed181 + 7220a01 commit 827af8fc1bd4aa643afc02506bb15778a24c0caa
Showing with 12 additions and 6 deletions.
  1. +12 −6 components/net/http_cache.rs
@@ -428,12 +428,14 @@ fn handle_range_request(
},
_ => continue,
};
if res_beginning - 1 < beginning && res_end + 1 > end {
let res_beginning_minus_one = res_beginning.checked_sub(1).unwrap_or(0);
let res_end_plus_one = res_end.checked_add(1).unwrap_or(1);
if res_beginning_minus_one < beginning && res_end_plus_one > end {
let resource_body = &*partial_resource.body.lock().unwrap();
let requested = match resource_body {
&ResponseBody::Done(ref body) => {
let b = beginning as usize - res_beginning as usize;
let e = end as usize - res_beginning as usize + 1;
let b = beginning.checked_sub(res_beginning).unwrap_or(0) as usize;
let e = end.checked_sub(res_beginning).unwrap_or(1) as usize;
body.get(b..e)
},
_ => continue,
@@ -474,7 +476,8 @@ fn handle_range_request(
} else {
continue;
};
if res_beginning < beginning && res_end == total - 1 {
let total_minus_one = total.checked_sub(1).unwrap_or(0);
if res_beginning < beginning && res_end == total_minus_one {
let resource_body = &*partial_resource.body.lock().unwrap();
let requested = match resource_body {
&ResponseBody::Done(ref body) => {
@@ -495,7 +498,7 @@ fn handle_range_request(
},
(&(Bound::Unbounded, Bound::Included(offset)), Some(ref complete_resource)) => {
if let ResponseBody::Done(ref body) = *complete_resource.body.lock().unwrap() {
let from_byte = body.len() - offset as usize;
let from_byte = body.len().checked_sub(offset as usize).unwrap_or(0) as usize;
let requested = body.get(from_byte..);
if let Some(bytes) = requested {
let new_resource =
@@ -519,7 +522,10 @@ fn handle_range_request(
} else {
continue;
};
if (total - res_beginning) > (offset - 1) && (total - res_end) < offset + 1 {
let offset_minus_one = offset.checked_sub(1).unwrap_or(0);
let offset_plus_one = offset.checked_add(1).unwrap_or(1);
if (total - res_beginning) > offset_minus_one && (total - res_end) < offset_plus_one
{
let resource_body = &*partial_resource.body.lock().unwrap();
let requested = match resource_body {
&ResponseBody::Done(ref body) => {

0 comments on commit 827af8f

Please sign in to comment.
You can’t perform that action at this time.