capnproto / capnproto-rust

Cap'n Proto for Rust
MIT License
2.06k stars 222 forks source link

Forbid use of as_slice when unaligned feature is enabled #497

Closed as-com closed 6 months ago

as-com commented 6 months ago

Somewhat related to #496 - if the user enables the unaligned feature, undefined behavior may result from use of as_slice() if the type is larger than 1 byte.

I added a compile-time check that panics in a const fn for a more useful error message and to keep the API the same. This also adds support for as_slice() on big-endian targets so long as the lists' elements are 1 byte or less.

Possible alternatives include:

codecov[bot] commented 6 months ago

Codecov Report

Attention: Patch coverage is 16.66667% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 51.69%. Comparing base (ab342b3) to head (9522881). Report is 4 commits behind head on master.

Files Patch % Lines
capnp/src/primitive_list.rs 16.66% 10 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #497 +/- ## ========================================== + Coverage 51.64% 51.69% +0.04% ========================================== Files 69 69 Lines 33735 33790 +55 ========================================== + Hits 17422 17467 +45 - Misses 16313 16323 +10 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

dwrensha commented 6 months ago

Thanks!