-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 CA2022 warnings (Avoid inexact read with 'Stream.Read') #100352
Changes from 2 commits
53cdd1d
d9ea36a
ba7d12c
8cf6b19
b94df00
79f13ef
7e1ed89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,7 +86,7 @@ | |
_bufferState = BufferState.Reading; | ||
_buffer = new byte[_stream.Length]; | ||
_stream.Position = 0; | ||
_stream.Read(_buffer, 0, _buffer.Length); | ||
_stream.ReadExactly(_buffer); | ||
Check failure on line 89 in src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/XmlBuffer.cs Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_AllConfigurations)src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/XmlBuffer.cs#L89
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
|
||
_writer = null; | ||
_stream = null; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,7 +121,7 @@ internal void PlayWaveFile(AudioData audio) | |
try | ||
{ | ||
byte[] data = new byte[(int)audio._stream.Length]; | ||
audio._stream.Read(data, 0, data.Length); | ||
audio._stream.ReadExactly(data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here |
||
Play(data); | ||
} | ||
finally | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,7 +174,7 @@ public Stream LoadResource(Uri uri, string mediaType) | |
int cLen = (int)stream.Length; | ||
MemoryStream memStream = new(cLen); | ||
byte[] ab = new byte[cLen]; | ||
stream.Read(ab, 0, ab.Length); | ||
stream.ReadExactly(ab); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically all of them :) |
||
_resourceLoader.UnloadFile(localPath); | ||
memStream.Write(ab, 0, cLen); | ||
memStream.Position = 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't compile as written. This library builds for multiple target frameworks, some of which don't have ReadExactly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I've added a check for
NET7_0_OR_GREATER
before usingReadExactly
.Is there a build target to check locally if I've used a function that is not available in a target framework? I ran the tests locally with
.\build.cmd -subset clr+mono+libs+libs.tests -test -rc Release
but got no build error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. That will only end up building for the current platform. There used to be a command for building all flavors of all libraries, but I can't find it in the docs now. @ViktorHofer? In the meantime, you can cd into the src folder for the library and
dotnet build
will build all targets for it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build.cmd libs -allconfigurations