Skip to content

[fix] serial: reject malformed envelope payloads and trailing data on loads (LET-26)#165

Merged
vt128 merged 1 commit into
masterfrom
fix/let-26-serial-strict
Jun 13, 2026
Merged

[fix] serial: reject malformed envelope payloads and trailing data on loads (LET-26)#165
vt128 merged 1 commit into
masterfrom
fix/let-26-serial-strict

Conversation

@vt128

@vt128 vt128 commented Jun 13, 2026

Copy link
Copy Markdown
Member

What

serial.loads violated its own "lossless round-trip or a clear error" contract (README) in two ways:

  1. Wrong-typed payloads coerced to empty values. Each tag decoder type-asserted the v payload and discarded the ok flag, so a payload of the wrong shape became the zero value instead of an error:

    • loads('{"$t":"tuple","v":123}') → empty tuple
    • loads('{"$t":"set","v":123}') → empty set
    • loads('{"$t":"mapkv","v":123}') → empty dict
    • loads('{"$t":"bytes","v":123}') → empty bytes

    (time/bigint did error, but reported the coerced "" rather than the real payload.)

  2. Trailing data silently dropped. loads decoded only the first JSON value: loads('1 2')1, loads('{"a":1}{"b":2}'){"a":1}.

Fix

Each decoder checks its type assertion and errors with invalid <tag> payload; loads rejects trailing content via dec.More() (trailing whitespace still passes). The README "Errors on" list is updated to match.

Test-first

New sections in serial_test.go cover the malformed-payload rejections and the trailing-data rejection; both fail before the fix.

Verification

go test -race -count=2 ./..., go vet, gofmt -l clean, Docker golang:1.19 race run green.

Requirement: LET-26

… loads

serial.loads violated its own "lossless or a clear error" contract in
two ways:

1. Each tag decoder type-asserted the "v" payload and discarded the ok
   flag, so a wrong-typed payload became the zero value instead of an
   error: loads('{"$t":"tuple","v":123}') returned an empty tuple,
   "set"/"mapkv" an empty set/dict, "bytes" empty bytes. (time/bigint
   already errored, but reported the coerced "" instead of the real
   payload.) Each decoder now checks the assertion and errors with
   "invalid <tag> payload".

2. loads decoded only the first JSON value and ignored the rest, so
   loads('1 2') returned 1. Reject trailing content with dec.More()
   (trailing whitespace still passes).

README "Errors on" list updated to match. Test-first: new sections in
serial_test cover both. Requirement: LET-26.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
@codacy-production

codacy-production Bot commented Jun 13, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 6 complexity · 0 duplication

Metric Results
Complexity 6
Duplication 0

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.03% coverage variation

Metric Results
Coverage variation +0.03% coverage variation (-1.00%)
Diff coverage 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (433eae0) 7692 7276 94.59%
Head commit (ff738c0) 7713 (+21) 7298 (+22) 94.62% (+0.03%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#165) 28 28 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.42%. Comparing base (433eae0) to head (ff738c0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #165      +/-   ##
==========================================
+ Coverage   93.39%   93.42%   +0.03%     
==========================================
  Files          49       49              
  Lines        6177     6191      +14     
==========================================
+ Hits         5769     5784      +15     
+ Misses        260      258       -2     
- Partials      148      149       +1     

☔ 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.

@vt128 vt128 merged commit 1bec4dd into master Jun 13, 2026
12 checks passed
@vt128 vt128 deleted the fix/let-26-serial-strict branch June 13, 2026 07:01
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