fix(parser): flat_byte_size — element-wise variant JOIN, not max#179
fix(parser): flat_byte_size — element-wise variant JOIN, not max#179avrabe wants to merge 1 commit into
Conversation
The mythos-auto delta-pass on PR #178 flagged that flat_byte_size computes the payload width of result<T,E> and variant as `max(flat_byte_size(arm))` rather than the Component Model's element-wise flatten_variant JOIN. `max` of arm byte totals underestimates whenever the arms flatten to a different *number* of core values. result<u64, string>: the ok arm u64 flattens to [i64] (8 B), the err arm string to [i32,i32] (8 B). The old form gave 4 + max(8,8) = 12, but the joined payload is [i64, i32] (12 B) and the true flat size is 4 + 12 = 16. Fix: flat_byte_size is rewritten over a new private flat_width_list helper that materialises each type's flat core-value width list and JOINs variant/result arms element-wise. Non-variant types are byte-for-byte unchanged. flat_width_list caps its length at FLAT_WIDTH_CAP (256); a type whose flattening exceeds the cap yields None and flat_byte_size returns u32::MAX, preserving the LS-P-4 saturation contract and bounding the helper's Vec against the LS-P-4 OOM class. The LS-P-4 regression test still passes. Disposition of the mythos-auto finding: the discover step claimed an OOB-write hazard. Rejected on validation — flat_byte_size has zero consumers in meld-core/src/; retptr return areas are sized by return_area_byte_size, a different function. No reachable hazard, no possible PoC, NOT a confirmed finding, no LS-N entry. This commit fixes the underlying arithmetic anyway, as correctness hygiene on a pub fn a future consumer could inherit. Regression test flat_byte_size_result_uses_element_wise_join_not_max pins result<u64,string>=16, an unequal-arity variant=16, the equal-arms result<u32,u32>=8, and non-variant record/u64 unchanged. Refs: mythos-auto finding on PR #178. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Mythos delta-pass requiredThis PR modifies one or more Tier-5 source files (per Before merge, run the Mythos discover protocol on the
Why this gate exists: LS-A-10 The gate check on this PR will pass once the label is |
LS-N verification gate✅ 19/19 approved LS entries verified
Approved Failed LS entries(none) Missing regression tests(none) Updated automatically by |
Mythos delta-pass (auto)❌ 1 finding(s) across 1 Tier-5 file(s)
Auto-run via |
Summary
Fixes the
flat_byte_sizecorrectness defect the mythos-auto delta-pass surfaced on PR #178 — the auto-runner's first real finding.flat_byte_sizecomputed the payload width ofresult<T,E>/variantasmax(flat_byte_size(arm))instead of the Component Model's element-wiseflatten_variantJOIN.maxof arm byte totals underestimates whenever the arms flatten to a different number of core values:result<u64, string>okarmu64[i64]errarmstring[i32, i32]4 + max(8, 8)[i32, i64, i32]Fix
flat_byte_sizeis rewritten over a new privateflat_width_listhelper that materialises each type's flat core-value width list (one entry per value, 4 or 8 bytes) and JOINsvariant/resultarms element-wise — joined length = longest arm, each position the wider arm width. Non-variant types (record, tuple, primitive, flags, …) are byte-for-byte unchanged.flat_width_listcaps its length atFLAT_WIDTH_CAP = 256(far past the canonical-ABI flat limit of 16). A nestedfixed-length-listexceeding the cap yieldsNone→flat_byte_sizereturnsu32::MAX. This preserves the LS-P-4 saturation contract (a saturated value fails downstream allocation safely rather than wrapping) and bounds the helper'sVecagainst the LS-P-4 OOM class. The LS-P-4 regression test still passes.Finding disposition (validate.md)
The discover step also claimed an OOB-write hazard — "adapter code sizes a retptr buffer from this value." Rejected on validation:
flat_byte_sizehas zero consumers inmeld-core/src/(only its own recursion + the LS-P-4 test); retptr return areas are sized byreturn_area_byte_size→canonical_abi_size_unpadded, a different function. No reachable hazard → no possible PoC → not a confirmed finding, no LS-N entry.This PR fixes the underlying arithmetic anyway — it's a correctness defect in a
pub fna future consumer would inherit. Hygiene, not a safety fix. (Full disposition: PR #178 thread.)Tests
flat_byte_size_result_uses_element_wise_join_not_maxpinsresult<u64,string>=16, an unequal-arity variant=16, equal-armsresult<u32,u32>=8, and non-variant record/u64 unchanged. Full meld-core lib suite 248 → 249.🤖 Generated with Claude Code