Commit Graph

12 Commits

Author SHA1 Message Date
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