Skip to content

Commit b8cf937

Browse files
Cherrypick "Fix issue with Checksum and long strings" to 17.9 (#9591)
Cherrypick "Fix issue with Checksum and long strings" to 17.9 * Fix issue with Checksum and long strings There is a logic error in Checksum.Builder that causes an ArgumentOutOfRangeException to be thrown on .NET Framework when a string larger than 4KB is appened. * Use WorkItem attribute --------- Co-authored-by: Dustin Campbell <[email protected]>
1 parent 8f4bea9 commit b8cf937

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/ChecksumTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,17 @@ public void TestTagHelperEquality()
143143
}
144144
}
145145
}
146+
147+
[Fact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1909377")]
148+
public void TestLargeString()
149+
{
150+
object? largeString = RazorTestResources.GetResourceText("FormattingTest.razor");
151+
152+
var builder = new Checksum.Builder();
153+
builder.AppendData(largeString);
154+
155+
var result = builder.FreeAndGetChecksum();
156+
157+
Assert.NotNull(result);
158+
}
146159
}

src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Utilities/Checksum.Builder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static void AppendData(HashingType hash, byte[] buffer, string value)
148148
var index = 0;
149149
while (index < stringBytes.Length)
150150
{
151-
var remaining = stringBytes.Length;
151+
var remaining = stringBytes.Length - index;
152152
var toCopy = Math.Min(remaining, buffer.Length);
153153

154154
stringBytes.Slice(index, toCopy).CopyTo(buffer);

0 commit comments

Comments
 (0)