-
Notifications
You must be signed in to change notification settings - Fork 0
Fix buffer overflow #3
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| using System.Buffers; | ||
| using System.Diagnostics; | ||
| using System.Text; | ||
| using RobotsTxt; | ||
|
|
@@ -1011,11 +1012,15 @@ public void TestGetPathParamsQuery(string url, string expected) | |
| [InlineData("/a/b/c", "/a/b/c")] | ||
| [InlineData("á", "%C3%A1")] | ||
| [InlineData("%aa", "%AA")] | ||
| [InlineData("%ab%c", "%AB%c")] | ||
ybastide marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [InlineData("test%", "test%")] | ||
| [InlineData("%a", "%a")] | ||
| public void TestMaybeEscapePattern(string url, string expected) | ||
| { | ||
| var actual = | ||
| Encoding.ASCII.GetString(RobotsTxtParser.MaybeEscapePattern(Encoding.UTF8.GetBytes(url)).ToArray()); | ||
| Encoding.ASCII.GetString(RobotsTxtParser.MaybeEscapePattern(Encoding.UTF8.GetBytes(url), out var dst).ToArray()); | ||
|
||
| Assert.Equal(expected, actual); | ||
| if (dst != null) ArrayPool<byte>.Shared.Return(dst); | ||
| } | ||
| } | ||
| } | ||
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.
Returning a span over a rented array that will be returned to the pool creates a potential use-after-free scenario. The caller receives a span pointing to memory that may be reused once
ArrayPool<byte>.Shared.Return(dst)is called. Consider either returning the array itself with the length, or copying the data to a new array before returning.