Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Buffer offset misuse #4481

Merged
merged 2 commits into from
Apr 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions core/src/types/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ impl Buffer {
parts, idx, offset, ..
} => {
let mut ret = Vec::with_capacity(parts.len() - *idx);
let mut new_offset = *offset;
for part in parts.iter().skip(*idx) {
ret.push(IoSlice::new(&part[*offset..]));
ret.push(IoSlice::new(&part[new_offset..]));
new_offset = 0;
}
ret
}
Expand Down Expand Up @@ -368,16 +370,16 @@ impl Buf for Buffer {
return 0;
}

let mut i = 0;
for part in parts.iter().skip(*idx) {
if i >= dst.len() {
break;
}

dst[i] = IoSlice::new(&part[*offset..]);
i += 1;
}
i
let mut new_offset = *offset;
parts
.iter()
.skip(*idx)
.zip(dst.iter_mut())
.map(|(part, dst)| {
*dst = IoSlice::new(&part[new_offset..]);
new_offset = 0;
})
.count()
}
}
}
Expand Down
Loading