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 two instances of undefined behavior in codec crate #7751

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
codec: Fix undefined behavior in try_decode_first tests
Previous code creates aliasing mutable slices.

Signed-off-by: Brian Anderson <[email protected]>
  • Loading branch information
brson committed May 7, 2020
commit 69b602a4a50370cf8f327116ec345a13c7083ce8
7 changes: 3 additions & 4 deletions components/codec/src/byte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,12 +1055,11 @@ mod tests {
let output_len = unsafe {
let src_ptr = buffer.as_mut_ptr().add(encoded_prefix_len);
let slice_len = buffer.len() - encoded_prefix_len;
let src = std::slice::from_raw_parts(src_ptr, slice_len);
let dest = std::slice::from_raw_parts_mut(src_ptr, slice_len);
let buf = std::slice::from_raw_parts_mut(src_ptr, slice_len);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is on purpose as L1069 says. There should either be some misunderstanding or the case should be removed.

/cc @breeswish

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, how about calling try_decode_first_internal instead?

if is_desc {
MemComparableByteCodec::try_decode_first_desc(src, dest).unwrap()
MemComparableByteCodec::try_decode_first_in_place_desc(buf).unwrap()
} else {
MemComparableByteCodec::try_decode_first(src, dest).unwrap()
MemComparableByteCodec::try_decode_first_in_place(buf).unwrap()
}
};
assert_eq!(output_len.0, encoded_len);
Expand Down