Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Fix bounds checking in PagedCharBuffer and related code #5354

Closed
wants to merge 2 commits into from

Conversation

dougbu
Copy link
Member

@dougbu dougbu commented Oct 3, 2016

  • PagedCharBuffer, Append(string value), never ending loop #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

@dougbu
Copy link
Member Author

dougbu commented Oct 3, 2016

/to @pranavkm since you're familiar w/ this code

}

[Fact]
public async Task FlushAsync_WritesContentToInner()
Copy link
Contributor

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?

Copy link
Member Author

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...

Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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))
Copy link
Contributor

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).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

w/in when in?

Copy link
Member Author

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.

Copy link
Contributor

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
Copy link
Contributor

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]);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆗

dougbu added 2 commits October 3, 2016 14:55
- #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
@dougbu dougbu force-pushed the dougbu/bounds.fix.5347 branch from 41aea40 to 2629717 Compare October 3, 2016 22:38
@dougbu
Copy link
Member Author

dougbu commented Oct 3, 2016

🆙📅

Copy link
Contributor

@pranavkm pranavkm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@dougbu
Copy link
Member Author

dougbu commented Oct 4, 2016

4e6fd82

@dougbu dougbu closed this Oct 4, 2016
@dougbu dougbu deleted the dougbu/bounds.fix.5347 branch October 4, 2016 17:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants