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

validate whether addr is null before constructing slice #194

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

YangKeao
Copy link
Member

Signed-off-by: YangKeao yangkeao@chunibyo.icu

Validate whether the address is null before trying to construct the slice. Because in debug build, the from_raw_parts will check whether the addr is null and aligned, if not, it will panic.

The embarrasing part is that this problem cannot be reproduced through test, so the current test cannot cover this situation...

@sticnarf
Copy link
Contributor

The embarrasing part is that this problem cannot be reproduced through test, so the current test cannot cover this situation...

Right... Though there is a assert_unsafe_precondition check in from_raw_parts , we almost always use the prebuilt libstd in release mode which eliminates the checks.

If we enable -Z build-std, we will reproduce the panic.

@sticnarf
Copy link
Contributor

I have no idea about the CI failures due to linking errors...

@YangKeao YangKeao force-pushed the fix-null-slice-construction branch 2 times, most recently from de55da0 to 851d881 Compare January 19, 2023 09:52
Signed-off-by: YangKeao <yangkeao@chunibyo.icu>
@tiberiusferreira
Copy link

tiberiusferreira commented Jan 6, 2024

Hey, as a data point, I just hit this and building with release did fix it.

I hit this specifically because I'm a M1 user. So first adding this crate and running it crashed. I read #187 and enabled the frame pointer feature flag, nightly and added -Z build-std.

Then I hit this.

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.

None yet

3 participants