Skip to content

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Sep 23, 2021

Backport of #59487 to release/6.0-rc2

/cc @stephentoub

Customer Impact

TextFieldParser has a variety of bugs that cause it to misbehave in various ways if the underlying Stream being read from returns less data than requested. This can manifest as giving back invalid data (e.g. strings containing lots of null characters) or missing data or various kinds of exceptions about failed parsing or an inability to grow the underlying buffer.

Testing

New tests in addition to the existing ones.

Risk

It's changing VB code, which I'm not a native speaker of 😄

Three bugs being fixed here:
1. The SlideCursorToStartOfBuffer method is incorrectly assuming that the buffer is filled to its end (that m_Buffer.Length = m_CharsRead).  As a result, two things happen.  First, we copy more data than is needed to the temporary buffer; that's just unnecessary but not harmful.  But second, when it issues a read to fill the remainder of the buffer, it does so at the wrong position, both leaving zeros in the buffer that end up getting parsed as real data and losing real data from the end.
2. IncreaseBufferSize assumes m_CharsRead = m_Buffer.Length, which may not be the case.  As with (1), this can result in it reading into the wrong part of the array and leaving garbage that gets processed.
3. IncreaseBufferSize is always increasing the buffer size, even if only a small portion of the buffer is used.  This can then result in the whole operation failing when it repeatedly increases the buffer size and ends up failing due to ticking over the max buffer threshold.

(1) doesn't exist in .NET Framework 4.8 but (2) and (3) do.  (1) is easily triggered by a stream that sporadically doesn't produce all the data requested; (2) and (3) end up needing a stream that frequently produces much less than requested.  This PR fixes all three.
@ghost
Copy link

ghost commented Sep 23, 2021

Tagging subscribers to this area: @cston
See info in area-owners.md if you want to be subscribed.

Issue Details

Backport of #59487 to release/6.0-rc2

/cc @stephentoub

Customer Impact

Testing

Risk

Author: github-actions[bot]
Assignees: -
Labels:

area-Microsoft.VisualBasic

Milestone: -

@cston
Copy link
Contributor

cston commented Sep 23, 2021

cc @jaredpar

@danmoseley danmoseley added the Servicing-consider Issue for next servicing release review label Sep 23, 2021
@jamshedd jamshedd added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Sep 23, 2021
@danmoseley danmoseley merged commit a628cce into release/6.0-rc2 Sep 23, 2021
@danmoseley danmoseley deleted the backport/pr-59487-to-release/6.0-rc2 branch September 23, 2021 18:07
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants