Skip to content

fix(lib): drop unreachable negative-length check in preflightProtoBytes - #562

Open
0xrlawrence wants to merge 1 commit into
canopy-network:mainfrom
0xrlawrence:fix/dead-unsigned-bounds-check
Open

fix(lib): drop unreachable negative-length check in preflightProtoBytes#562
0xrlawrence wants to merge 1 commit into
canopy-network:mainfrom
0xrlawrence:fix/dead-unsigned-bounds-check

Conversation

@0xrlawrence

Copy link
Copy Markdown

Description

preflightProtoBytes guards a length-delimited field with:

if l < 0 || offset+int(l) > len(b) {

protowire.ConsumeVarint returns a uint64, so l < 0 can 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

  • Removed the dead l < 0 clause.
  • Added a comment recording why the int(l) conversion it appeared to guard is in fact safe: the preceding protoMaxFieldBytes check bounds l to 32MB. This is so the next reader does not re-add the check.

Testing

  • go build ./...
  • go test ./lib/ passes
  • staticcheck no longer reports SA4003 in lib/util.go

No behaviour change.

🤖 Generated with Claude Code

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant