Repository navigation
fix(seq): an inline row past its capacity is INVALID, not InvalidArgument - #187
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
An inline (heap-free) row of a nested array decoded through
FixedMessageSeqwas read with no stated bound. A row announcing more elements than the row's capacity was therefore refused by the destination check asInvalidArgument(CORELIB_PLAN §6.6.3), notINVALID.Repro (generator
tests/matrix/corpus/defs/nested_rows.yaml,numrows:array<array<u32, count 3>>; target cpp,corelib: c-cpp,allow_dynamic: false), input26 03 04 01020304 07(row 0 announces 4 elements, count is 3):status: INVALID_ARGUMENT,decode error: INVALID_ARGUMENT,streamdecode: decode error: INVALID_ARGUMENTstatus: INVALID,decode error: INVALID,streamdecode: decode error: INVALIDThe control, a row of exactly 3 elements (
26 03 03 010203 07), staysCOMPLETE. Theallow_dynamic: truevariant already answeredINVALID.Rule
MESSAGE_SPEC §7.1: "A schema
count: Non 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 sameINVALIDoutcome."An inline row's capacity is the schema
countit was generated for (theFixedMessageSeqdoc already says so, and it already applies the same reading to the outer index).Fix
FixedMessageSeq::deserializepassesfixed_capacity_v<Elem>as the bound toreadArrayfor a native-scalar row, so the count check (INVALID) runs before the destination check.readArraywith no stated bound still getsInvalidArgument(§6.6.3); encode-side behaviour is untouched.Tests
test_seq.cpp: the test that pinned the old answer ("a row longer than the row's own capacity is InvalidArgument") now assertsInvalidMessage, with the rationale in its comment.REQUIRE( in.feed(...).code() == sofab::Error::InvalidMessage )failed,2 == 4; test_cpp 183/184. After: all 5 CTest suites pass.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-staticNestedRowsharness now answersINVALIDon the repro bytes. Thec-cpp-staticpin intests/conformance/cpp/run.sh(ROWS_WANT=INVALID_ARGUMENT) has to be flipped toINVALIDwhen this lands.Found by sofa-buffers/generator#642