Skip to content

Fix stale values when reusing binary decode targets - #127

Open
dailyun wants to merge 1 commit into
samber:masterfrom
dailyun:codex/binary-decode-reuse
Open

dailyun wants to merge 1 commit into
samber:masterfrom
dailyun:codex/binary-decode-reuse

Conversation

@dailyun

@dailyun dailyun commented Oct 20, 2026

Copy link
Copy Markdown

Decoding a binary value into a reused Option or Either can retain data from its previous value. For example, decoding Some({Count: 0, Values: {"new": 2}}) over a value containing Count: 7 and an "old" map key leaves the count and old key behind. Gob omits zero-valued struct fields and merges into existing maps.

Decode each selected value into a fresh variable, then assign it after successful decoding. This covers Option and every branch of Either/Either3/Either4/Either5 without changing the encoded format.

Added 30 regression cases across the 15 container branches, using both direct binary decoding and the public gob encoder/decoder. All 30 fail before the fix and pass afterward. Full race tests, build, vet, staticcheck, golangci-lint (0 issues), and formatting checks pass on Go 1.26.7/macOS arm64. Older supported Go versions are left to CI.

This intentionally replaces the selected value instead of merging it with the previous payload. No dependencies changed.

Prepared and tested with OpenAI Codex; not human-reviewed before submission.

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