-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix bounds checking in PagedCharBuffer
and related code
#5354
Conversation
/to @pranavkm since you're familiar w/ this code |
} | ||
|
||
[Fact] | ||
public async Task FlushAsync_WritesContentToInner() |
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 looks identical to the previous test. What am I missing here?
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.
Could add the new assertion to the previous test. But they're really looking for unrelated things in the same scenario. Could change the previous test's name and merge the two. LMK if you feel strongly...
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.
It's fine. I just wasn't sure if this was a copy-paste error
|
||
public override void Return(char[] buffer, bool clearArray = false) | ||
{ | ||
Returned.Add(buffer); |
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.
Could this just no-op?
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 using Returned
in new test that uses this. But seemed better to be consistent w/ the other test ArrayPool<T>
here.
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.
🙈
// Imitate ArrayPool<char>.Shared as it falls back from its default char[1024] Bucket to the next one. | ||
var bufferSource = new Mock<ICharBufferSource>(); | ||
bufferSource | ||
.SetupSequence(s => s.Rent(PagedCharBuffer.PageSize)) |
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.
💯
var expected = Enumerable.Repeat('d', 2 * PagedCharBuffer.PageSize); | ||
var laterString = new string('d', PagedCharBuffer.PageSize); | ||
|
||
// Act (loop w/in second Append(string) call). |
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.
w/in when in?
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.
I'll spell out "within" which is what I meant w/in this comment.
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.
💩
// Arrange | ||
// Imitate ArrayPool<char>.Shared as it falls back from its default char[1024] Bucket to the next one. | ||
var bufferSource = new Mock<ICharBufferSource>(); | ||
bufferSource |
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.
Could you also add a test for the reverse sequence i.e.
.Returns(new char[2 * PagedCharBuffer.PageSize])
.Returns(new char[PagedCharBuffer.PageSize]);
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.
🆗
- #5347 - inconsistent bounds checking caused problems after `ArrayPool<char>` fell back to `new char[2048]` - would fail a `Debug` assertion in Debug builds and loop endlessly in Release builds - change to `CacheTagHelper+CharBufferHtmlContent` is for correctness only - always uses a `CharArrayBufferSource` and that returns arrays of the exact size requested
41aea40
to
2629717
Compare
🆙📅 |
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.
ArrayPool<char>
fell back tonew char[2048]
Debug
assertion in Debug builds and loop endlessly in Release buildsCacheTagHelper+CharBufferHtmlContent
is for correctness onlyCharArrayBufferSource
and that returns arrays of the exact size requested