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

Fix snippet buffered read logic #8560

Merged
merged 1 commit into from
Oct 24, 2022
Merged

Conversation

Kissaki
Copy link
Contributor

@Kissaki Kissaki commented Oct 22, 2022

The snippet generates a file with 215 bytes.
It reads the file with a 1024 byte buffer.
While this works with a new 0-initialized buffer, the buffered reading misses using the returned read bytes count.
A file with > 1024 bytes will reuse the now non-0 buffer and print unintended values.

Fix buffered reading to be technically correct and work for arbitrary file contents.

Fixes #4141

@Kissaki Kissaki requested a review from a team as a code owner October 22, 2022 17:58
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Oct 22, 2022
@ghost
Copy link

ghost commented Oct 22, 2022

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

The snippet generates a file with 215 bytes.
It reads the file with a 1024 byte buffer.
While this works with a new 0-initialized buffer, the buffered reading misses using the returned read bytes count. A file with > 1024 bytes will reuse the now non-0 buffer and print unintended values.

Fix buffered reading to be technically correct and work for arbitrary file contents.

Fixes #4141

Author: Kissaki
Assignees: -
Labels:

area-System.IO, community-contribution

Milestone: -

The snippet generates a file with 215 bytes.
It reads the file with a 1024 byte buffer.
While this works with a new 0-initialized buffer, the buffered reading misses using the returned read bytes count.
A file with > 1024 bytes will reuse the now non-0 buffer and print unintended values.

Fix buffered reading to be technically correct and work for arbitrary file contents.

Fixes dotnet#4141
@opbld33
Copy link

opbld33 commented Oct 22, 2022

Learn Build status updates of commit b017ccc:

✅ Validation status: passed

File Status Preview URL Details
snippets/csharp/System.IO/FileStream/Overview/fstream class.cs ✅Succeeded View

For more details, please refer to the build report.

Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report.

For any questions, please:

@opbld34
Copy link

opbld34 commented Oct 22, 2022

Learn Build status updates of commit b054d8c:

✅ Validation status: passed

File Status Preview URL Details
snippets/csharp/System.IO/FileStream/Overview/fstream class.cs ✅Succeeded View

For more details, please refer to the build report.

Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report.

For any questions, please:

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @Kissaki !

@adamsitnik
Copy link
Member

The CI leg is red due to missing solution file. I've verified manually that the provided code builds fine:

PS D:\projects\repros\docs8560> dotnet build -c Release
MSBuild version 17.4.0-preview-22428-01+14c24b2d3 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
C:\Program Files\dotnet\sdk\7.0.100-rc.1.22431.12\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInferen
ce.targets(219,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-poli
cy [D:\projects\repros\docs8560\docs8560.csproj]
  docs8560 -> D:\projects\repros\docs8560\bin\Release\net7.0\docs8560.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.40

@adamsitnik adamsitnik merged commit 01cefbe into dotnet:main Oct 24, 2022
@Kissaki Kissaki deleted the fix-snippet branch June 4, 2024 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.IO community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FileStream example bug
4 participants