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

Closed
wants to merge 1 commit into from

Conversation

YangKeao
Copy link
Member

Signed-off-by: YangKeao [email protected]

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...

@YangKeao YangKeao requested a review from sticnarf January 19, 2023 08:26
@YangKeao YangKeao force-pushed the fix-null-slice-construction branch from d8d85b9 to 83aff0f Compare January 19, 2023 08:29
@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
@YangKeao YangKeao force-pushed the fix-null-slice-construction branch from 851d881 to 0ee067d Compare January 19, 2023 10:00
@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.

@YangKeao
Copy link
Member Author

YangKeao commented Nov 7, 2024

It has been fixed in #255.

@YangKeao YangKeao closed this Nov 7, 2024
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.

3 participants