fix(lib): drop unreachable negative-length check in preflightProtoBytes - #562
Open
0xrlawrence wants to merge 1 commit into
Open
fix(lib): drop unreachable negative-length check in preflightProtoBytes#5620xrlawrence wants to merge 1 commit into
0xrlawrence wants to merge 1 commit into
Conversation
protowire.ConsumeVarint returns a uint64, so 'l < 0' can never be true and staticcheck reports it as SA4003. The check reads as protection against a negative length that the type system already rules out. The int(l) conversion it appeared to guard is in fact made safe by the preceding protoMaxFieldBytes check, which bounds l to 32MB. Replaced the dead clause with a comment recording why the conversion is safe, so the next reader does not re-add it. No behaviour change.
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.
Description
preflightProtoBytesguards a length-delimited field with:protowire.ConsumeVarintreturns auint64, sol < 0can never be true. staticcheck reports it as SA4003. It reads as protection against a negative length that the type system already rules out.Changes Made
l < 0clause.int(l)conversion it appeared to guard is in fact safe: the precedingprotoMaxFieldBytescheck boundslto 32MB. This is so the next reader does not re-add the check.Testing
go build ./...go test ./lib/passeslib/util.goNo behaviour change.
🤖 Generated with Claude Code