-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[SR-6361] Fix Data.withUnsafeMutableBytes() for slices with length < range.lowerBound #1314
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
[SR-6361] Fix Data.withUnsafeMutableBytes() for slices with length < range.lowerBound #1314
Conversation
@swift-ci please test |
Just curious, maybe Data.withUnsafeBytes() followed the same logic and should be fixed too? |
TestFoundation/TestNSData.swift
Outdated
("test_validateMutation_slice_mutableBacking_withUnsafeMutableBytes_lengthLessThanLowerBound", test_validateMutation_slice_mutableBacking_withUnsafeMutableBytes_lengthLessThanLowerBound), | ||
("test_validateMutation_slice_customBacking_withUnsafeMutableBytes_lengthLessThanLowerBound", test_validateMutation_slice_customBacking_withUnsafeMutableBytes_lengthLessThanLowerBound), | ||
("test_validateMutation_slice_customMutableBacking_withUnsafeMutableBytes_lengthLessThanLowerBound", | ||
test_validateMutation_slice_customMutableBacking_withUnsafeMutableBytes_lengthLessThanLowerBound) |
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.
If you finish this line with a comma (like in like 511) then others won't need to change line 517 when they add more tests in the future.
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 @alblue, I updated the commit
@phausler the tests pass on this; do you think the change is reasonable? |
@my0114 thanks for your feedback! You might be right, I will check it in a couple of hours to make sure. |
@swift-ci please test |
1 similar comment
@swift-ci please test |
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.
Good catch, can you please put up this as a PR on the overlay as well?
thanks @phausler, sure, this is the PR: swiftlang/swift#12898 |
@phausler I'm sorry for changing this PR after review but I tried to investigate the issue further and realized that simple |
Solves SR-6361
This code snippet:
crashes with:
fatal error: UnsafeMutableRawBufferPointer with negative count
because
count
was not calculated correctly (_offset
was not taken into account)The existing tests were not covering this case because it works correctly for data slices when _length > range.lowerBound.
I created new tests for this exact situation but I can also update the existing ones by adding one more check to them.
Please, let me know what you think.