-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[stdlib] Fix unsafe String.write_bytes()
#3773
[stdlib] Fix unsafe String.write_bytes()
#3773
Conversation
Signed-off-by: martinvuyk <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix! A few questions:
- Is there a unit test we can add to expose this bug?
- Should we add a
debug_assert
to ensure the argument towrite_bytes
is not null terminated per the doc string?
Signed-off-by: martinvuyk <[email protected]>
I added a debug assert for the null termination, still there can be the case of data with a 0 somewhere in the middle but I'll leave a
I don't think there is one, since this was a call to a private method |
LGTM when CI is passing |
I think what you have is fine wrt the |
Signed-off-by: martinvuyk <[email protected]>
I mean theoretically we could, just need to find a way for the allocation to be just on the limit of a page and try to access that to get a segfault 😆 |
Signed-off-by: martinvuyk <[email protected]>
@JoeLoser one problem, in Python unlike C you might actually have a string >>> print(repr("\0"), bytes("\0", "utf8"))
'\x00' b'\x00' luckily we had tests that caught this |
!sync |
✅🟣 This contribution has been merged 🟣✅ Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the nightly branch during the next Mojo nightly release, typically within the next 24-48 hours. We use Copybara to merge external contributions, click here to learn more. |
[External] [stdlib] Fix unsafe `String.write_bytes()` Fix an unsafe assumption that the span is null terminated. Co-authored-by: martinvuyk <[email protected]> Closes #3773 MODULAR_ORIG_COMMIT_REV_ID: 4b07e6d189015a2053b6f8f3a5a0249ab00b3b1f
Landed in 194b24b! Thank you for your contribution 🎉 |
[External] [stdlib] Fix unsafe `String.write_bytes()` Fix an unsafe assumption that the span is null terminated. Co-authored-by: martinvuyk <[email protected]> Closes modularml#3773 MODULAR_ORIG_COMMIT_REV_ID: 4b07e6d189015a2053b6f8f3a5a0249ab00b3b1f
[External] [stdlib] Fix unsafe `String.write_bytes()` Fix an unsafe assumption that the span is null terminated. Co-authored-by: martinvuyk <[email protected]> Closes modularml#3773 MODULAR_ORIG_COMMIT_REV_ID: 4b07e6d189015a2053b6f8f3a5a0249ab00b3b1f Signed-off-by: Manuel Saelices <[email protected]>
Fix an unsafe assumption that the span is null terminated.