fix: resolve 5 bugs in .NET managed layer#34
Merged
xoofx merged 1 commit intoxoofx:masterfrom Mar 12, 2026
Merged
Conversation
- use CryptographicOperations.FixedTimeEquals in Hash.Equals for constant-time comparison - only hash bytes actually read in Blake3Stream.Read(Span<byte>) - only hash bytes actually read in Blake3Stream.ReadAsync(Memory<byte>) - remove dead null check on ReadOnlySpan in Hasher.UpdateWithJoin - validate negative offset in Hasher.Finalize(long, Span<byte>)
Owner
|
Thank you! |
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.
Summary
Hash.Equalsis not constant-time:SequenceCompareToshort-circuits on the first differing byte, making it vulnerable to timing attacks. Replaced withCryptographicOperations.FixedTimeEquals. This contradicts the doc comment which states "constant-time equality checking".Blake3Stream.Read(Span<byte>)hashes wrong data: when the buffer is larger than the data available, the entire buffer (including unread garbage bytes) is hashed instead of only the bytes actually read. Fixed by slicing tolength.Blake3Stream.ReadAsync(Memory<byte>)same issue: the async overload has the identical bug. Fixed the same way.Hasher.UpdateWithJoinincorrect empty span handling:ReadOnlySpan<byte> == nullis equivalent to checkingIsEmpty, which causesUpdateWithJointo throwArgumentNullExceptionon empty input. This is inconsistent withUpdateandUpdateWithJoin<T>, which accept empty spans without throwing. Removed the check.Hasher.Finalize(long, Span<byte>)missing negative offset validation: a negativelongis silently cast to a hugeulong. AddedArgumentOutOfRangeException.ThrowIfLessThan(offset, 0).