16 Commits

Author SHA1 Message Date
b56408e2d7 rbf0_encode: check record shapes before reading offsets
The short-count change read the offset of every attribute and content
record before the shape checks, so a malformed record (None, a number or
a string in attributes/content) raised TypeError or AttributeError
instead of the documented EncodeError "value". This broke four
subtests of test_bool_recorded_lengths_and_malformed_element_children on
current main, as reported by reviewers (CHANGES_REQUESTED on #2386).

Move the attributes/content shape checks ahead of the offset lists, and
add a regression subtest with a flagged element and malformed records.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 11:11:41 +01:00
8a95eac1ca Merge commit 'refs/pr-all/2386' into carry/2386 2026-12-02 11:06:25 +01:00
4f1ca18964 rbf0_encode: write back a short-count element with text or child content (RBF0-ENCODE-SHORT-COUNT-CONTENT)
docs/rbf0.md 9.6: an element short of its attribute count is refused
only when it has a value in its content, because that value would
decode as an attribute. rbf0_tree also sets attribute_order_violation
when text or a child element arrives before the count is reached, and
the encoder refused every flagged element as "an attribute after
content", so such an element was refused although its bytes write back
exactly (an element short of its count with no content already encoded,
as tested).

Refuse on the flag only when an attribute record's offset follows the
first content record's, or when records carry no offsets to tell (a
hand-built tree fails closed as before). The short-count check for a
value in the content is unchanged.

Tested: test_fewer_attribute_records_than_the_count now also encodes a
short-count element with text and with a child element exactly (both
refused before) and refuses them once the offsets are removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 17:52:05 +01:00
e8baf7f7cf rbf0_encode: fail closed on malformed descriptors/nodes/lengths/float overflow and harden CLI 2026-11-25 05:49:14 +01:00
bbf2cf1119 rbf0_encode: refuse invalid descriptor names 2026-11-24 00:39:02 -05:00
c70e673e12 rbf0_encode: fail report export when resources are refused (#6560)
Squash-merged after diff review of PR #6560
2026-11-23 12:44:31 -06:00
13c8a8fed9 Merge pull request #3811 from gbezzuoli 2026-11-22 17:03:56 -05:00
ade14c9fa7 Merge pull request #3384 from Shrey Ratna 2026-11-22 17:01:48 -05:00
3cf5d32a31 Merge pull request #3379 from kapitche 2026-11-22 17:01:46 -05:00
a2f8aae55c rbf0_encode: --check fails on a refused resource; refuse attribute records the count does not cover (BUILD-1084)
Four findings by @HQasper on tools/rbf0_encode.py:

- `--check` exited 0 when resources were refused, so a round trip that verified nothing read as success.
  It now exits 0 only when every resource is byte-identical, as rbf0_tree.py does for a resource that is
  not ok.
- The element header count came from `attrs_declared` while every node of `attributes` was written, so an
  attribute appended by hand encoded as the element's first content value: a different tree with status
  ok. encode() now refuses more attribute records than the count (value), and an element short of its
  count that has a value in its content, which would decode as an attribute (order). A parsed element
  short of its count with no such value still round-trips exactly.
- `blob[:doc["size"]]` in resources() could not trim anything. The slice is gone and check() compares
  the joined length with the recorded size; two carved streams of one name are refused instead of the
  last one silently winning.
- docs/rbf0.md 9.6 lists the `value` refusals and says what `--check` exits with.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 18:46:57 -03:00
6b1b479aa2 rbf0_encode: a non-UTF-8 report is a one-line error, not a UnicodeDecodeError traceback 2026-11-22 15:19:44 -05:00
d17c0975d2 Merge pull request #3215 from Leo Leahy 2026-11-22 15:15:47 -05:00
0264ef1e5f fix(rbf0_encode): refuse unpaired Unicode surrogates 2026-11-22 20:05:12 +00:00
251b00d688 rbf0_encode: reject conflicting names on reused descriptor indices 2026-11-22 16:42:54 -03:00
f616da931f rbf0_encode: fail closed on malformed reports, bool indices, direct NaN, and float32 overflow
Harden tools/rbf0_encode.py so edited/malformed trees and JSON reports raise clean EncodeError / SystemExit messages instead of tracebacks: reject bool for descriptor/attrs_declared, catch direct math.nan and struct.pack OverflowError in float_bits(), reject non-dict documents and non-str text, and validate report JSON/shape/offsets/OSError in write_all(). Synthetic tests added in tests/test_rbf0_encode.py.
2026-11-22 17:10:56 +00:00
5d4285f383 rbf0_encode: write an rbf0_tree document back to bytes, with a round-trip check
docs/rbf0.md called the tree output "a rendering, not a round-trip" and
nothing wrote RBF0. encode(doc) rebuilds the record stream from the tree
rbf0_tree.parse_resource returns, in both layouts: descriptor names at
first use, element words 0, 0, attribute count, attributes then content
in tree order, text and strings with their recorded NUL.

It fails closed, with a reason, when the tree cannot hold the original:
an incomplete parse, invalid UTF-8 the decoder replaced, a NaN float
(infinities are exact), an attribute after content, a descriptor out of
order, or a string or text whose byte length changed.

--check decodes, encodes and compares every resource of a carve and
prints counts only. A report-and-directory form writes the resources of
an rbf0_tree.py JSON report (possibly edited) as .rbf files.

Measured on the 1,263 data.rpf resources: 1,240 byte-identical, 0
different, 23 refused, all for invalid UTF-8. They are the resources
holding the 26 invalid payloads docs/rbf0.md already lists. Counts are
in docs/rbf0.md 9.6.

tests/test_rbf0_encode.py: synthetic streams only. Every record type in
both widths, infinities, narrow float bits, the largest integers, the
JSON report form, an edited tree, each refusal reason, and the CLI with
a resource split over two 64 KiB streams.
2026-11-22 12:30:26 -03:00