Repository navigation
[Microsoft.Android.Build.Tasks] Modernize SHA256 hashing - #13608
Merged
Merged
Conversation
FastDeploy and MIBC profile generation created disposable SHA256 instances to hash single UTF-8 inputs. Use the static span-based API for these one-shot operations and share the bounded UTF-8 buffering logic. This preserves the FastDeploy lowercase hexadecimal manifest hash and the deterministic MIBC BlobContentId while avoiding intermediate UTF-8 and formatted-string allocations. Validation: * dotnet build src/Microsoft.Android.Build.Tasks/Microsoft.Android.Build.Tasks.csproj -v minimal * dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj -v minimal --filter FullyQualifiedName~FastDeployTests|FullyQualifiedName~GenerateMibcProfileTests (72 passed) Co-authored-by: Copilot App <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the SHA256 hashing modernization.
No open issues 🎉
What changed in this PR
Modernizes one-shot SHA256 hashing in the Android build tasks while preserving FastDeploy manifest hashes and deterministic MIBC content identifiers.
Changes:
- Adds a shared UTF-8 hashing helper with stack allocation for inputs up to 256 bytes.
- Replaces disposable SHA256 instances with the static span-based API.
- Uses direct lowercase hexadecimal formatting for FastDeploy hashes.
| File | Description |
|---|---|
src/Microsoft.Android.Build.Tasks/Utilities/MibcProfileWriter.cs |
Uses the shared helper to generate deterministic content hashes. |
src/Microsoft.Android.Build.Tasks/Utilities/HashingHelper.cs |
Adds bounded UTF-8 buffering and static SHA256 hashing. |
src/Microsoft.Android.Build.Tasks/Tasks/FastDeploy.Manifest.cs |
Uses stack-allocated hash storage and direct lowercase hexadecimal formatting. |
Review effort: Balanced
9 tasks
| { | ||
| using var sha256 = SHA256.Create (); | ||
| byte[] hash = sha256.ComputeHash (Encoding.UTF8.GetBytes (fingerprint)); | ||
| byte[] hash = new byte [SHA256.HashSizeInBytes]; |
Member
There was a problem hiding this comment.
🤖 This is the best we can do here. BlobContentId.FromHash only has public byte[] and ImmutableArray<byte> overloads (the ReadOnlySpan<byte> one is private), so stackalloc is not possible. ArrayPool would cost more than one 32-byte allocation that runs once per MIBC write.
jonathanpeppers
approved these changes
Nov 18, 2026
jonathanpeppers
deleted the
simonrozsival-modernize-sha256-hashing-fba
branch
November 18, 2026 16:05
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FastDeploy and MIBC profile generation were still constructing disposable
System.Security.Cryptography.SHA256instances for one-shot UTF-8 inputs. The owning task assembly targetsnet12.0, so these call sites can use the static, span-based hashing APIs without affecting thenetstandard2.0Maven download code.Use a shared
HashingHelper.Sha256Utf8()implementation with bounded stack allocation for ordinary inputs. FastDeploy continues to emit the same lowercase hexadecimal manifest hash, while MIBC profile generation continues to derive the same deterministicSystem.Reflection.Metadata.BlobContentId.Validation:
dotnet build src/Microsoft.Android.Build.Tasks/Microsoft.Android.Build.Tasks.csproj -v minimal— passeddotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj -v minimal --filter 'FullyQualifiedName~FastDeployTests|FullyQualifiedName~GenerateMibcProfileTests'— 72/72 passedgit diff --check— passed