Skip to content

Fix binary decoding into reused decimal receivers - #48

Closed
ryanduguid wants to merge 1 commit into
quagmt:masterfrom
ryanduguid:fix/binary-decoder-reuse
Closed

ryanduguid wants to merge 1 commit into
quagmt:masterfrom
ryanduguid:fix/binary-decoder-reuse

Conversation

@ryanduguid

@ryanduguid ryanduguid commented Oct 1, 2026 •

Copy link
Copy Markdown

Summary

Fix silent coefficient retention when UnmarshalBinary reuses a decimal receiver. A valid padded input can give 1.23 a big-integer representation; decoding -4.56 into that receiver then returns -1.23 without an error. Sequential gob decoding exposes the same receiver-state defect.

previous coefficient + incoming coefficient -> incoming coefficient only

Both decoder helpers now replace the complete coefficient through the existing constructors. This clears inactive storage while preserving copied values, sign, precision and the binary format.

Evidence

  • Before: 29 of 50 focused leaf subcases fail on upstream, including storage transitions and repeated gob decoding.
  • After: All 50 pass, checking exact representations, generated-byte re-encoding, zero, signs, precision 19, padded small values and immutable copies. All 200 public binary/gob observations agree; upstream has 42 mismatches.
  • Selecting an individual gob subcase also passes; earlier records are consumed before the subcase assertions.
  • Full Linux race/coverage suites pass on Go 1.23.0 and 1.27.1, with 97.8% and 98.1% library statement coverage. Native Windows Go 1.27.1 unit/coverage tests, regressions and deterministic fuzz seeds pass.
  • The extended binary fuzz target passes a further 60-second run with 2,995,366 executions. All 21 configured targets pass make fuzz-all 20 in an integration run using only PR Fix division panics from oversized trial quotients #47's published division helper as an overlay.
  • Focused 386 regressions and fuzz seeds pass. Full 386 retains the same five failing test names, including the parent, as unchanged upstream.
  • Measured allocation counts match upstream across nine decoder transitions: small destinations use zero allocations; big destinations use two on Go 1.27.1. Scoped lint has zero new findings; full lint retains seven identical baseline findings.

Risk

Previously retained coefficients now become the incoming value. The big path still allocates a fresh integer so copied decimals remain immutable. Existing validation and malformed-input behaviour remain.

Unverified

Upstream Test and Fuzz are waiting for approval. The full fuzz run on this branch alone stops at the separate division panic fixed by #47. Full lint and the 386 suite have the same failures as master. Native Windows race tests (no gcc), macOS and timing were not checked.

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