-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Build.Tasks] make CA2022 an error (#9282)
I was building Xamarin.Android.Build.Tasks and noticed some CA2022 warnings that scared me: src\Xamarin.Android.Build.Tasks\Utilities\AssemblyCompression.cs(77,6): warning CA2022: Avoid inexact read with 'System.IO.FileStream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022) src\Xamarin.Android.Build.Tasks\Utilities\MonoAndroidHelper.cs(186,8): warning CA2022: Avoid inexact read with 'System.IO.FileStream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022) Some cases like this were actually ok: byte[] publicKey = new byte[stream.Length]; stream.Read (publicKey, 0, publicKey.Length); // ... name.PublicKey = SigningHelper.GetPublicKey (publicKey); Because it uses `stream.Length` for the `byte[]` size, we don't need to use the return value of `Read()`. Looking at another place, however: sourceBytes = bytePool.Rent (checked((int)fi.Length)); // ... fs.Read (sourceBytes, 0, (int)fi.Length); // ... destBytes = bytePool.Rent (LZ4Codec.MaximumOutputSize (sourceBytes.Length)); This actually is a bug, as it rents a `destBytes` array potentially a bit larger than bytes read. This made me think, we should make CA2022 an error and fix them all. I also updated `MonoAndroidHelper.SizeAndContentFileComparer` to just use the `Files.HashFile()` method. This is probably faster than the previous code, anyway.
- Loading branch information
1 parent
87f1cd6
commit ac8a922
Showing
12 changed files
with
39 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters