-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix: Stop lonely hyphens from causing panic #411
Conversation
The method `starts_with` as implemented for the `OsStrExt2` trait on `OsStr` assumed that the needle given is shorter than the haystack. When this is not the case, the method panics due to an attempted out-of-bounds access on the byte representation of `self`. Problematic if, say, an end-user gives us `"-"` and the library tries to see if that starts with `"--"`. Fortunately, slices already implement a `starts_with` method, and we can delegate to it. This *does* create a semantics change: if both `self` and the needle have length 0, this implementation will return `true`, but the old implementation would return `false`. Based on the test suite still passing, acknowledging the vacuous truth doesn't seem to cause any problems. Fixes #410
Thanks for the pull request, and welcome! The team is excited to review your changes, and you should hear from @kbknapp (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
📌 Commit 85b1146 has been approved by |
fix: Stop lonely hyphens from causing panic The method `starts_with` as implemented for the `OsStrExt2` trait on `OsStr` assumed that the needle given is shorter than the haystack. When this is not the case, the method panics due to an attempted out-of-bounds access on the byte representation of `self`. Problematic if, say, an end-user gives us `"-"` and the library tries to see if that starts with `"--"`. Fortunately, slices already implement a `starts_with` method, and we can delegate to it. This *does* create a semantics change: if both `self` and the needle have length 0, this implementation will return `true`, but the old implementation would return `false`. Based on the test suite still passing, acknowledging the vacuous truth doesn't seem to cause any problems. Fixes #410
fix: Stop lonely hyphens from causing panic The method `starts_with` as implemented for the `OsStrExt2` trait on `OsStr` assumed that the needle given is shorter than the haystack. When this is not the case, the method panics due to an attempted out-of-bounds access on the byte representation of `self`. Problematic if, say, an end-user gives us `"-"` and the library tries to see if that starts with `"--"`. Fortunately, slices already implement a `starts_with` method, and we can delegate to it. This *does* create a semantics change: if both `self` and the needle have length 0, this implementation will return `true`, but the old implementation would return `false`. Based on the test suite still passing, acknowledging the vacuous truth doesn't seem to cause any problems. Fixes #410
☀️ Test successful - status |
The method
starts_with
as implemented for theOsStrExt2
trait onOsStr
assumed that the needle given is shorter than the haystack. Whenthis is not the case, the method panics due to an attempted
out-of-bounds access on the byte representation of
self
. Problematicif, say, an end-user gives us
"-"
and the library tries to see if thatstarts with
"--"
.Fortunately, slices already implement a
starts_with
method, and we candelegate to it.
This does create a semantics change: if both
self
and the needlehave length 0, this implementation will return
true
, but the oldimplementation would return
false
. Based on the test suite stillpassing, acknowledging the vacuous truth doesn't seem to cause any
problems.
Fixes #410