Skip to content

fix: validate 32-bit declared lengths in the buffer decoder (v2) - #144

Merged
shamaton merged 1 commit into
v2from
fix/buffer-length-32bit-v2
Oct 20, 2026
Merged

shamaton merged 1 commit into
v2from
fix/buffer-length-32bit-v2

Conversation

@shamaton

Copy link
Copy Markdown
Owner

Summary

  • v2 port of the buffer decoder 32-bit length validation from main
  • Reject 32-bit declared lengths that don't fit in int instead of panicking
  • Remove offset/length arithmetic that could overflow on 32-bit platforms

Background / Motivation

Same issue as on v3: on 32-bit platforms, high-bit Array32/Map32/Str32/Bin32/Ext32 lengths became negative ints, causing panics or silently accepting malformed input.

Changes

  • Same changes as main
  • LengthFromUint32 placed in the existing decodingutil guard file (v2 has no range.go)

Test Plan

  • go vet ./... / go test -race ./... pass
  • Same regression test as main, verified on linux/386: fails/panics before the fix, passes after
  • Decode benchmarks vs v2: geomean −0.3%; B/op and allocs/op unchanged

On 32-bit platforms, Array32/Map32/Str32/Bin32 lengths with the high bit
set became negative ints, causing panics or silently accepting malformed
input. Declared lengths are now validated with LengthFromUint32 (shared
with the stream decoder), and offset arithmetic no longer overflows.

Ext32 lengths are validated as well.
@github-actions github-actions Bot added the type: bug Confirmed or likely defect label Oct 20, 2026
@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.77778% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.84%. Comparing base (0f8f4e8) to head (cbc4f1c).

Files with missing lines Patch % Lines
internal/decoding/struct.go 64.70% 3 Missing and 3 partials ⚠️
internal/common/decodingutil/guard.go 50.00% 1 Missing and 1 partial ⚠️
internal/decoding/bin.go 50.00% 1 Missing and 1 partial ⚠️
internal/decoding/ext.go 50.00% 1 Missing and 1 partial ⚠️
internal/decoding/map.go 60.00% 1 Missing and 1 partial ⚠️
internal/decoding/slice.go 50.00% 1 Missing and 1 partial ⚠️
internal/decoding/string.go 50.00% 1 Missing and 1 partial ⚠️
internal/stream/decoding/struct.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##               v2     #144      +/-   ##
==========================================
- Coverage   98.08%   97.84%   -0.25%     
==========================================
  Files          74       74              
  Lines        5993     6019      +26     
==========================================
+ Hits         5878     5889      +11     
- Misses         67       74       +7     
- Partials       48       56       +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shamaton
shamaton merged commit e8ca255 into v2 Oct 20, 2026
21 checks passed
@shamaton
shamaton deleted the fix/buffer-length-32bit-v2 branch October 20, 2026 12:51
@github-actions github-actions Bot mentioned this pull request Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Confirmed or likely defect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant