-
Notifications
You must be signed in to change notification settings - Fork 306
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
Audit use of unsafe in uri/mod.rs #417
Open
sbosnick
wants to merge
7
commits into
hyperium:master
Choose a base branch
from
sbosnick:audit_uri_mod
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
86e5c15
Add tests for Uri::try_from() for &[u8]
sbosnick ce01f23
Add another test for an invalid Uri from &[u8]
sbosnick 0126801
Add more test of invalid UTF-8
sbosnick b5fcf4a
Refactor parse_full() in uri/mod
sbosnick 2850d83
Add comments to uses of unsafe in uri/mod.rs
sbosnick c7bc09b
Fix build error on nightly
sbosnick 8e6758e
Revert "Fix build error on nightly"
sbosnick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This used to just assume
empty()
, and now its callingparse(s)?
, right?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.
Not exactly. It used to assume
PathAndQuery::empty()
and now it is callingPathAndQuery::from_shared(s)
wheres
is an emptyBytes
. We know thats
is an emptyBytes
because we test thatauthority_end
equals the whole length ofs
at line 821 (of the changed file) and then calls.split_to(authority_end)
at line 831. This latter call becomes (in this case)s.split_to(s.len())
which results ins
being left empty.PathAndQuery::empty()
andPathAndQuery::from_shared(s)
wheres
is empty both produce aPathAndQuery
withdata
the equivalent ofByteStr::new()
andquery
asNONE
(the sentinel value declared inuri::path
).Logically this change still produces the same result in the
scheme.is_none()
case.Performance wise, this particular case isn't covered by any of the existing benchmarks in
benches/uri.rs
. AlthoughPathAndQuery::from_shared(s)
in general is linear in the size ofs
, whens
is empty this a constant operation, though this doesn't answer the performance question without having benchmarks.If there are any concerns about the performance implications of this change I would be happy to add a benchmark to
benches/uri.rs
to cover this case.