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

KnownLayout::validate_cast #349

Conversation

joshlf
Copy link
Member

@joshlf joshlf commented Sep 7, 2023

This method is a core primitive that other parts of the codebase can build on to validate casts and compute the appropriate pointer metadata which should result from those casts. Future commits will build on top of this one to make use of it.

@joshlf joshlf marked this pull request as draft September 7, 2023 21:03
@joshlf joshlf force-pushed the try-from-bytes-raw-argument-to-is-bit-valid-2-validate-size-align branch from bc5ca1d to f3f998e Compare September 7, 2023 21:28
src/lib.rs Outdated Show resolved Hide resolved
@joshlf joshlf force-pushed the try-from-bytes-raw-argument-to-is-bit-valid-2-validate-size-align branch 5 times, most recently from 547c468 to f72320b Compare September 8, 2023 07:38
@jswrenn jswrenn force-pushed the try-from-bytes-raw-argument-to-is-bit-valid-2-validate-size-align branch from f72320b to da9e996 Compare September 8, 2023 20:21
@joshlf joshlf force-pushed the try-from-bytes-raw-argument-to-is-bit-valid-2-validate-size-align branch 7 times, most recently from ed49647 to 90bee71 Compare September 9, 2023 00:06
@joshlf joshlf changed the title [WIP] KnownLayout::validate_size_align KnownLayout::validate_cast Sep 9, 2023
@joshlf
Copy link
Member Author

joshlf commented Sep 9, 2023

@jswrenn Another thing to call out: I still need to determine whether there are isize overflow issues. The function itself doesn't have any, of course, but will it ever be used in a context where it needs to either a) handle checking for isize overflow or, b) require that the caller make isize-related guarantees?

I think the answer is no: Given an address/length of a sound allocation (ie, one that safe Rust could produce):

  • The length cannot overflow isize
  • The address plus length cannot overflow usize

Those are the preconditions to the pointer add method. Note that the address + length sum doesn't have to fit in an isize, just in a usize. The isize overflow issues only apply to offsets within the allocation, not to addresses.

That's certainly consistent with the use in the TryFromBytes PR. Just wanted to put it in your head in case you see something that I'm missing.

@joshlf joshlf force-pushed the try-from-bytes-raw-argument-to-is-bit-valid-2-validate-size-align branch 4 times, most recently from 5159709 to 80c12cf Compare September 11, 2023 22:28
src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
@joshlf joshlf requested a review from jswrenn September 11, 2023 22:31
@joshlf joshlf marked this pull request as ready for review September 11, 2023 22:31
@joshlf joshlf force-pushed the try-from-bytes-raw-argument-to-is-bit-valid-2-validate-size-align branch from 80c12cf to 2c9e7f1 Compare September 12, 2023 01:40
This method is a core primitive that other parts of the codebase can
build on to validate casts and compute the appropriate pointer metadata
which should result from those casts. Future commits will build on top
of this one to make use of it.

Co-authored-by: Jack Wrenn <jswrenn@amazon.com>
@joshlf joshlf force-pushed the try-from-bytes-raw-argument-to-is-bit-valid-2-validate-size-align branch from 2c9e7f1 to bbf9603 Compare September 12, 2023 02:22
@jswrenn jswrenn merged commit 9803616 into main Sep 12, 2023
150 checks passed
@jswrenn jswrenn deleted the try-from-bytes-raw-argument-to-is-bit-valid-2-validate-size-align branch September 12, 2023 12:08
@joshlf joshlf restored the try-from-bytes-raw-argument-to-is-bit-valid-2-validate-size-align branch September 12, 2023 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants