Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/libraries/System.Private.Uri/src/System/UriExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,12 @@ public static bool TryUnescapeDataString(ReadOnlySpan<char> charsToUnescape, Spa
return false;
}

if (destination.Length < indexOfFirstToUnescape)
{
charsWritten = 0;
return false;
}

// We may throw for very large inputs (when growing the ValueStringBuilder).
scoped ValueStringBuilder vsb;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,18 @@ static void ValidateUnescape(string input, string expectedOutput)
}
}

[Theory]
[InlineData("aa%", 0)]
[InlineData("aa%", 1)]
[InlineData("aaa%41", 0)]
[InlineData("aaa%41", 1)]
[InlineData("aaa%41", 2)]
public void TryUnescapeDataString_SmallDestination_ReturnsFalse(string input, int destinationLength)
{
Assert.False(Uri.TryUnescapeDataString(input, new char[destinationLength], out int charsWritten));
Assert.Equal(0, charsWritten);
}

[Fact]
public void UriEscapeUnescapeDataString_LongInputs()
{
Expand Down
Loading