Skip to content

refactor(decode): delete the unreachable dispatchOne header parser (#88) - #106

Merged
Andste82 merged 1 commit into
mainfrom
refactor/88-drop-unreachable-dispatchone
Aug 9, 2026
Merged

Andste82 merged 1 commit into
mainfrom
refactor/88-drop-unreachable-dispatchone

Conversation

@Andste82

@Andste82 Andste82 commented Aug 9, 2026

Copy link
Copy Markdown
Member

The finding

IStreamImpl::dispatchOne was a third copy of the field-header parser, private and called from nowhere — grep -rn dispatchOne found only its definition and a stale @ref in the §7.3 doc comment.

Being dead, it had drifted away from the two live copies (parseFieldHeader, dispatchLevel) and enforced none of the ceilings they do:

  • the fixlen word without fixlenWordValid() (§4.6),
  • the array count without the ARRAY_MAX check (§6.2),
  • the array fixlen word without arrayFixlenWordValid() (§4.8),
  • and every truncation folded into error_, i.e. INCOMPLETE input reported as INVALID.

Wiring it up would have re-opened the hole nestedArrayCountCeiling() was added for: 05 <count=2^62> 20 takes the count * element_size skip, wraps size_t to zero bytes, and a message §6.2 requires to be INVALID decodes COMPLETE.

The change

  • Delete dispatchOne.
  • The one doc comment that named it now points at the parsers that actually do the §7.3 skip — parseTopLevel at the top level, dispatchLevel inside a sequence.

No public API and no wire behaviour changes: the function was private and unreachable.

Regression test

headerParsersEnforceCeilings() in test/test_roundtrip.cpp, wired into the normal suite, in two halves:

  1. Byte-driven — the §4.6/§4.8/§6.2 violations (fixlen-array count 2^62, integer-array count 2^31, reserved fixlen subtype, string element in a fixlen array) are fed through the callback entry point, the API a per-field dispatcher serves, and must all be InvalidMessage; a legal fp32 array still decodes.
  2. Structural — a parser no entry point reaches cannot be caught by feeding bytes, so the test also scans include/sofab/sofab.hpp (path baked in by CMake, same trick test_vectors uses for the shared vectors) and requires every (id<<3)|type decode site to carry fixlenWordValid, arrayFixlenWordValid and ARRAY_MAX.

Half 2 fails on the parent commit with three failures naming sofab.hpp:4381 — the dead parser — and passes here. The README's test_roundtrip bullet documents the structural check.

Closes #88.

`dispatchOne` was a third copy of the field-header parser, private to the
input stream and called from nowhere. Being dead, it had drifted: it read
the fixlen word without `fixlenWordValid` (§4.6), the array count without
the ARRAY_MAX ceiling (§6.2) and the array fixlen word without
`arrayFixlenWordValid` (§4.8), and it folded every truncation into
`error_`, i.e. it would have reported INCOMPLETE input as INVALID. Wiring
it up would have re-opened exactly the hole `nestedArrayCountCeiling()`
closed: `05 <count=2^62> 20` takes the `count * element_size` skip, wraps
size_t to zero bytes and decodes COMPLETE a message §6.2 requires to be
INVALID.

Delete it, and point the one doc comment that named it (`@ref dispatchOne`
on the §7.3 tag-match seam) at the two parsers that actually perform the
skip, `parseTopLevel` and `dispatchLevel`.

`headerParsersEnforceCeilings()` guards both halves of this. It drives the
§4.6/§4.8/§6.2 violations through the callback entry point — the API a
per-field dispatcher serves — and, because an unreachable parser cannot be
reached by feeding bytes at all, also scans the header source and requires
every `(id<<3)|type` decode site to carry the three ceiling checks. That
structural half fails on the parent commit, naming sofab.hpp:4381.

Closes #88.
@Andste82
Andste82 merged commit 4e99509 into main Aug 9, 2026
7 checks passed
@Andste82
Andste82 deleted the refactor/88-drop-unreachable-dispatchone branch August 9, 2026 08:40
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.

6.2: Delete the unreachable IStreamImpl::dispatchOne, a third header parser that skips the §4.6/§4.8/§6.2 validation

1 participant