Skip to content

fix(seq): an inline row past its capacity is INVALID, not InvalidArgument - #187

Merged
Andste82 merged 1 commit into
mainfrom
fix/nested-row-over-capacity-invalid
Oct 2, 2026
Merged

Andste82 merged 1 commit into
mainfrom
fix/nested-row-over-capacity-invalid

Conversation

@Andste82

@Andste82 Andste82 commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Problem

An inline (heap-free) row of a nested array decoded through FixedMessageSeq was read with no stated bound. A row announcing more elements than the row's capacity was therefore refused by the destination check as InvalidArgument (CORELIB_PLAN §6.6.3), not INVALID.

Repro (generator tests/matrix/corpus/defs/nested_rows.yaml, numrows: array<array<u32, count 3>>; target cpp, corelib: c-cpp, allow_dynamic: false), input 26 03 04 01020304 07 (row 0 announces 4 elements, count is 3):

  • before (main 4754ec8): status: INVALID_ARGUMENT, decode error: INVALID_ARGUMENT, streamdecode: decode error: INVALID_ARGUMENT
  • after: status: INVALID, decode error: INVALID, streamdecode: decode error: INVALID

The control, a row of exactly 3 elements (26 03 03 010203 07), stays COMPLETE. The allow_dynamic: true variant already answered INVALID.

Rule

MESSAGE_SPEC §7.1: "A schema count: N on an array ... are wire-validity bounds, not sizing hints. They bind every implementation, regardless of its allocation strategy: a heap-less target that pre-sizes a buffer from the bound and a heap target that allocates per message MUST both reject input that exceeds it, with the same INVALID outcome."

An inline row's capacity is the schema count it was generated for (the FixedMessageSeq doc already says so, and it already applies the same reading to the outer index).

Fix

  • FixedMessageSeq::deserialize passes fixed_capacity_v<Elem> as the bound to readArray for a native-scalar row, so the count check (INVALID) runs before the destination check.
  • A row handed straight to readArray with no stated bound still gets InvalidArgument (§6.6.3); encode-side behaviour is untouched.
  • One argument added to an existing call; no new heap use, no new code path.

Tests

  • test_seq.cpp: the test that pinned the old answer ("a row longer than the row's own capacity is InvalidArgument") now asserts InvalidMessage, with the rationale in its comment.
  • Before the fix: REQUIRE( in.feed(...).code() == sofab::Error::InvalidMessage ) failed, 2 == 4; test_cpp 183/184. After: all 5 CTest suites pass.
  • Also green: full suite under ASan+UBSan (Debug, with the C++ smoke and freestanding targets), 6/6.
  • Not run locally: the clang / cross-compiled / QEMU / AVR jobs of CI (see CI on this PR).

Footprint

One constant argument on an existing call; I did not run the per-target size bench, so no byte numbers are claimed.

Generator

With this checkout as SOFAB_C_DIR, the generator's c-cpp-static NestedRows harness now answers INVALID on the repro bytes. The c-cpp-static pin in tests/conformance/cpp/run.sh (ROWS_WANT=INVALID_ARGUMENT) has to be flipped to INVALID when this lands.

Found by sofa-buffers/generator#642

…ment

FixedMessageSeq read a native-scalar row into inline storage with no stated
bound, so a row announcing more elements than the row's capacity was refused
by the destination check (InvalidArgument, §6.6.3). The row's capacity is the
schema count it was generated for, and MESSAGE_SPEC §7.1 makes an element past
a declared bound INVALID on every target. Pass the capacity as the bound, as
the doc comment already said it was.

Found by sofa-buffers/generator#642
@Andste82
Andste82 merged commit 2c99398 into main Oct 2, 2026
25 of 26 checks passed
@Andste82
Andste82 deleted the fix/nested-row-over-capacity-invalid branch October 2, 2026 16:17
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