You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TextFieldParser does not correctly handle input from streams that don't fill out the full array provided. #58857
Microsoft.VisualBasic.FileIO.TextFieldParser does not cope properly with stream reads that return fewer characters than requested. Note that the documentation for Stream.Read() is clear that this is possible:
"The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.
...
An implementation is free to return fewer bytes than requested even if the end of the stream has not been reached."
Notice that on line 828 / 735 within IncreaseBufferSize():
Dim CharsRead As Integer = m_Reader.Read(TempArray, m_Buffer.Length, DEFAULT_BUFFER_LENGTH)
This assumes that m_Buffer is full at the time the buffer is expanded, but it may not be, due to the fact that Stream.Read() may have previously returned fewer bytes than requested. The true length of m_Buffer can be found in m_CharsRead.
This behaviour has caused issues for us when parsing a file that has been provided to a web controller, as the stream does not fully fill the buffer provided.
changed the title [-]TextFieldParser does correctly handle input from streams that don't fill out the full array provided.[/-][+]TextFieldParser does not correctly handle input from streams that don't fill out the full array provided.[/+]on Sep 14, 2021
Activity
cston commentedon Sep 13, 2021
It looks like the current behavior is unchanged from .NET Framework. Moving to next milestone since this is not a regression.
[-]TextFieldParser does correctly handle input from streams that don't fill out the full array provided.[/-][+]TextFieldParser does not correctly handle input from streams that don't fill out the full array provided.[/+]stephentoub commentedon Sep 22, 2021
It actually does appear to be a regression. The cited function is the same, but SlideCursorToStartOfBuffer is different (and wrong) in core. The code in core appears to have come from reference source (https://github.com/microsoft/referencesource/blob/5697c29004a34d80acdaf5742d7e699022c64ecd/Microsoft.VisualBasic/runtime/msvbalib/FileIO/TextFieldParser.vb#L776-L799), which is for some reason not in sync with what's actually in the .NET Framework 4.8 binaries.
cston commentedon Sep 24, 2021
@nhunt-zf, thanks for logging this issue!