Skip to content
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

Rare off-by-one edge case in header-aware visitor #16

Closed
airbreather opened this issue Jul 18, 2019 · 1 comment
Closed

Rare off-by-one edge case in header-aware visitor #16

airbreather opened this issue Jul 18, 2019 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@airbreather
Copy link
Owner

private unsafe void VisitHeaderChunk(byte* b, int byteCount, bool flush)
{
int charCount = _headerDecoder.GetCharCount(b, byteCount, flush);
if (_headerBufferConsumed + charCount <= _headerBuffer.Length)
{
fixed (char* c = &_headerBuffer[_headerBufferConsumed])

If the input chunks were cut precisely before the byte that denotes the end of a header whose length is exactly equal to the configured max header length, and everything's valid UTF-8, then this method will be called one last time with an empty input.

_headerBufferConsumed will be equal to _headerBuffer.Length, which is actually supposed to be OK when charCount is 0, since we're not actually going to write anything into the array... but since that index is outside the array, it actually throws an exception.

@airbreather airbreather added the bug Something isn't working label Jul 18, 2019
@airbreather airbreather added this to the 1.2.0 milestone Jul 18, 2019
@airbreather airbreather self-assigned this Jul 18, 2019
@airbreather
Copy link
Owner Author

Found this when updating the test suite to improve coverage for the header-aware visitor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant