fix(anatomy): R5.4 review drawings bounded per annotation, report tables summed, docs counts
This commit is contained in:
1 parent
29eb499539
commit
411e1058c0
9 files changed
+271
-36
No files matched your search
@@ -0,0 +1,125 @@
|
||||
SECURITY — VERDICT: BLOCK(1)
|
||||
TOOL: semgrep 1.168.0 — p/security-audit, p/secrets, p/owasp-top-ten
|
||||
SCOPE: 29 files
|
||||
BLOCKING:
|
||||
1. [HIGH] review-drawings-amplification — crates/core/src/curation/draft/pipeline.rs:209 (bound at :205, projection at :211; amplifier reached through crates/core/src/curation/draft/app_review.rs:33 → crates/core/src/anatomy/layer.rs:108-118) — the 64 MiB review-drawing bound projects only the cleaned drawing repeated per view; every unnamed detail trigger copies the opened view's fr and en names four times into review/app-<view>.svg, so T triggers × a view name of S bytes write 4·T·S bytes unchecked: a 485,140-byte changes.json produced a 131,713,082-byte app-main.svg (no refusal), a 1,202,892-byte changes.json made the run abort on a 1 GiB allocation under a 3 GB cap, about 44 GiB at the 16 MiB read cap — hint: project each view's layer bytes before render_layer (per annotation: fixed overhead + geometry text + 4 × the name it carries, the opened view's names for an unnamed trigger) and refuse past MAX_REVIEW_DRAWINGS_BYTES together with the cleaned-drawing projection; add a test with unnamed triggers opening a long-named view; correct the RUST.md §11.14 row
|
||||
REPORTED (non-blocking):
|
||||
- [LOW] report-tables-bound-per-table — crates/core/src/curation/markdown.rs:162 (and changelog.rs:118)
|
||||
- [LOW] report-guard-stale-doc — crates/core/src/curation/report_guard.rs:14
|
||||
- [LOW] record-weight-omits-position — crates/core/src/curation/draft/records.rs:187
|
||||
- [LOW] test-lint-relaxation (convention, not a scanner suppression) — crates/core/tests/curation_markdown.rs:6, crates/core/tests/curation_review.rs:6
|
||||
PROOF: semgrep 162 rules on 29 files → 0 findings; checklist 12 checks → 5 findings
|
||||
|
||||
## Scope and method
|
||||
|
||||
Range `c6e0d85..HEAD` (HEAD 29eb499), paths `crates/core`, `packages/anatomy/tests`,
|
||||
`docs/development/RUST.md`: 29 added or modified files, all scanned by semgrep (162 rules
|
||||
loaded from the three pinned packs, 0 results, 0 errors).
|
||||
|
||||
Checklist, in order: hardcoded secrets (none), SQL by string building (none in the diff; the
|
||||
seed SQL writer is unchanged R5.3 code), unsanitised render (Markdown reports and SVG drawings,
|
||||
below), sensitive endpoint authz (none: a local CLI and a library), internals surfaced to a user
|
||||
(CLI stderr on a developer machine, not applicable), secrets in logs (none), tracked `.env` or
|
||||
credential (only `.env.example`, outside the diff), guardrails scanner (`--domain api,supabase`:
|
||||
0 FAIL, 1 WARN in `supabase/migrations/20261008110000_anatomical_sheets.sql:1177`, outside the
|
||||
diff, dropped), new suppressions (two test headers, LOW below), then the brief's threat model:
|
||||
Markdown parity against Prettier 3.8.3, resource bounds (records, tables, drawings), CLI file
|
||||
system confinement, SVG well-formedness.
|
||||
|
||||
Probes live in the session scratchpad, never in the repository:
|
||||
`/tmp/claude-1000/-home-bchanot-Documents-faunosteo/9b0edf59-ccd2-4662-b90c-e473dd78028e/scratchpad/probe`
|
||||
(a crate with a path dependency on `crates/core`, feature `curation`; `src/main.rs` wraps
|
||||
`report_guard::format_report`, `src/bin/amplify.rs` runs the draft pipeline in memory on the
|
||||
committed seed plus one extra change), `.../scratchpad/scripts/fmt.mjs` (the repository's
|
||||
Prettier 3.8.3 with the options of `packages/anatomy/src/format.ts`) and
|
||||
`.../scratchpad/scripts/{gen,gen2,widths,strong,diff}.py` (case generators and the
|
||||
differential). Nothing was written to the seed or any tracked file.
|
||||
|
||||
## Finding 1 (HIGH): the review-drawing bound does not cover the markers
|
||||
|
||||
`pipeline::review_drawings` refuses before rendering when
|
||||
`cleaned_svg.len() * 2 * views > MAX_REVIEW_DRAWINGS_BYTES` (64 MiB). RUST.md §11.14 states the
|
||||
guarantee as "review drawings past 64 MiB in all, projected before any is rendered … refused
|
||||
before rendering". The projection counts the cleaned drawing only. The application drawing of a
|
||||
view (`app_review::render_app_review_drawing` → `anatomy::layer::render_layer`) writes, for each
|
||||
detail trigger without a name of its own, the opened view's French and English names into
|
||||
`data-anno-name-fr`, `data-anno-name-en` and the `<title>` text `fr / en`: four copies of the
|
||||
view name per trigger. Nothing caps a view name (the sheet contract has no label length) or the
|
||||
number of triggers opening one view (integrity only requires the trigger to sit in the opened
|
||||
view's parent).
|
||||
|
||||
An authored change of one `set view:head name {fr: S bytes, en: S bytes}` and T `add document
|
||||
annotations` of unnamed detail triggers in `main` opening `head` passes the applier, the records
|
||||
bound, the 200,000-value document bound and the integrity gate, then writes about 4·T·S bytes in
|
||||
`review/app-main.svg`:
|
||||
|
||||
| S (per language) | T | changes.json | result |
|
||||
|---|---|---|---|
|
||||
| 1,024 | 10 | 166,322 B | 2.87 MB in all (baseline) |
|
||||
| 32,768 | 1,000 | 485,140 B | `review/app-main.svg` 131,713,082 B written, no refusal, peak RSS 429 MB |
|
||||
| 262,144 | 2,000 | 1,202,892 B | `memory allocation of 1073741824 bytes failed`, SIGABRT under `ulimit -v 3000000` (peak RSS 2.65 GB) |
|
||||
|
||||
At the read cap the records bound allows about S = 2 MiB and T = 5,600 (the set records 4·S
|
||||
units, each add about 1,500), so the tool would try to build about 44 GiB from a 5.4 MB
|
||||
changeset. `pnpm r5:import-equine --check` and `--out` both build every file before comparing or
|
||||
writing, so either mode dies on such a changeset. The TypeScript has the same amplification;
|
||||
the defect is that the port's declared bound, the control the round-8 fix introduced for this
|
||||
class, does not hold.
|
||||
|
||||
Reproduce: `cd .../scratchpad && (ulimit -v 4000000; ./probe/target/release/amplify 32768 1000)`.
|
||||
|
||||
Fix direction: project each view's drawing bytes before `render_layer`: the cleaned drawing,
|
||||
plus, per annotation of the view, a fixed overhead, its geometry text and four times the name
|
||||
bytes it carries (own name, or the opened view's names through `localized_names` for an
|
||||
unnamed trigger), plus the overlay's markers; refuse the sum past the bound. Freeze it with a
|
||||
test of unnamed triggers opening a long-named view, and restate the §11.14 row.
|
||||
|
||||
## LOW findings
|
||||
|
||||
- `markdown.rs:162` / `changelog.rs:118`: `MAX_TABLE_COLUMNS_TOTAL` bounds each table, not the
|
||||
report. The three level tables of the CHANGELOG can each approach 32 Mi columns: a synthetic
|
||||
raw report with three 6,000-row tables and one 5,300-byte cell each was admitted and aligned
|
||||
into 97,356,707 bytes (peak RSS 272 MB). Reaching it through the applier takes about 18,000
|
||||
records, at the edge of the 16 Mi-unit records bound. Bounded, consistent with the RUST.md
|
||||
wording ("an aligned report table"); a whole-report bound would make the worst case explicit.
|
||||
- `report_guard.rs:14-17`: the module doc says a code span admits "anything but a carriage
|
||||
return or a tab"; `generated_code` (`:186-193`) admits only `[A-Za-z0-9_:/. -]`, as RUST.md
|
||||
states. The code is the stricter one; the doc of the control is stale.
|
||||
- `records.rs:187-197`: `op_weight` does not charge the `position` anchor of an `add` or a
|
||||
`move` (`{"after": …}` / `{"before": …}`), which each record clones. One record per such op
|
||||
and the anchor must name an existing sibling, so the total stays under the changeset size:
|
||||
no amplification, the weight model is only incomplete.
|
||||
- `tests/curation_markdown.rs:6`, `tests/curation_review.rs:6`:
|
||||
`#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]` in two new
|
||||
integration-test files. The same header is on every test file of the crate, and `clippy.toml`
|
||||
says "Tests and the worker binary allow these lints locally where they own I/O". The library's
|
||||
I/O and clock ban stays enforced in `src/`. This is not a scanner-finding suppression, so it
|
||||
does not block.
|
||||
|
||||
## What held
|
||||
|
||||
- Markdown guard against Prettier 3.8.3: 189,394 generated reports in the templates of
|
||||
`changelog.rs` and `review_report.rs` (list items, bibliography, vet-flag lines, eight-column
|
||||
rows with `cell()` escaping). The cases cover random token mixes, admitted-only mixes, every
|
||||
code point from U+00A0 to U+33FF plus one in three up to U+2FFFF, in a table cell and in a
|
||||
list line, and `**word**` over the same letters. Result: 99,447 admitted, every admitted one
|
||||
byte for byte equal to Prettier, 0 silent differences. Structure forging (headings, list
|
||||
items, links, HTML, autolinks, references, code spans from authored text) is refused at the
|
||||
guard or at `assert_single_line` / `assert_authored`.
|
||||
- Records: every producer goes through `charge` (`ops.rs`, `rename.rs`, `apply.rs`
|
||||
marking). Raw report rows are bounded with the records. Aligned tables are refused before
|
||||
they are built. The guard and the aligner are linear per line.
|
||||
- SVG: element and attribute names are the generator's. Values and texts are escaped (`&`,
|
||||
`<`, `>`, `"`, tab, LF, CR). `first_unwritable` refuses non-XML-1.0 code points and CR. No
|
||||
author text can open a script or an href.
|
||||
- `--check`: byte identity, and the tree fallback only for `review/app-*` with the declared rule,
|
||||
after the committed file rebuilds from its tree. The committed drawing goes through the core
|
||||
reader first (depth cap), and `roxmltree` keeps its DTD refusal. Reads are confined to the
|
||||
canonical seed and capped at 16 MiB. A symlinked folder is never walked.
|
||||
- `--out`: no `..`, the parent is canonicalised, the final symlink is refused, the destination
|
||||
must be absent or empty, and it is refused inside the seed by path and by (dev, inode) over
|
||||
the whole seed tree. Writes use `create_dir` / `create_new`, never truncate, never delete.
|
||||
The check-to-write swap is the single-user residual already declared (§11.13).
|
||||
- Oracle generators (`packages/anatomy/tests/r5.*.test.ts`) write only under
|
||||
`MAKE_R5_ORACLES=1`, into `crates/core/tests/oracles/r5`. The Rust tests write only under
|
||||
the target folder.
|
||||
@@ -70,6 +70,12 @@ Fresh verifier and security on the fixed commit: below.
|
||||
- Security (`.claude/audits/2026-10-23-rust-r5-review-security-9.md`): HIGH records weight undercount: the change's reference ids at one unit per byte while each cloned id costs ≈56 bytes (200,000 one-character ids × 100 set ops: 948 MB before the bound; 16.4 MB file: 1.67 GB). MEDIUM `parse_changeset` ≈65× the input (1.075 GB at 16.4 MB; R5.3, outside the diff); MEDIUM guardrails WARN in a migration outside the diff; LOW test allows. Not covered: markers and labels bound of the drawings.
|
||||
- Fixed: every cloned string (texts, ids, op strings, object keys) weighs 64 + its bytes (`records::text_weight`; equine 1,965,944, bound 8.5× above); ids case added to `the_records_bound_holds_inside_one_op_and_the_marking`; parse amplification declared in §11.15 (owner decision on a lower input cap); RUST.md row updated.
|
||||
|
||||
## Round 10
|
||||
## Round 10 on 29eb499: verifier C1 to C8 MET, C9 NOT-MET (stale counts) + 10 FLOOR (audit prose), security BLOCK(1); `pnpm check:all` green 15:38:01
|
||||
|
||||
- Verifier: 47,470 TS-vs-Rust Markdown cases 0 silent (the unguarded aligner gave 34 on the same inputs), 117 SVG label cases bytes or declared rule. C9: RUST.md counts stale (review tests 9 → 10, suites, draft lines 4,385 → 4,532) and the `report_guard.rs` header ("anything but CR or tab" inside code spans). Info: "`<` before a letter" means an ASCII letter; number cells 24 bytes where a JS number prints 25.
|
||||
- Security (`.claude/audits/2026-10-23-rust-r5-review-security-10.md`): HIGH the drawings bound counted the cleaned drawing only: an unnamed trigger copies the opened view's names four times (485 KB changeset → 131 MB `app-main.svg`; 1.2 MB → abort at 3 GB). LOW tables bound per table (three level tables ≈97 MB together); LOW stale `report_guard.rs` header; LOW add/move position anchor not charged; LOW test allows.
|
||||
- Fixed: drawings projected as an upper bound per annotation (`pipeline::review_drawings_bytes`: 1,024 + 24 × (JSON text + longest view name) per annotation of the view, overlay's two documents and the app drawing; equine 1,390,428), test `unnamed_triggers_repeating_a_long_view_name_are_refused_before_rendering`; CHANGELOG tables bound summed over the three level tables (`assert_table_bound` with a running total), number cells 25; position anchor charged (equine records 1,966,163); `report_guard.rs` header; RUST.md counts (draft 4,600 lines, tests 11/2/18/5/3/7), ASCII letter wording, rows rewritten.
|
||||
|
||||
## Round 11
|
||||
|
||||
Fresh verifier and security on the fixed commit: below.
|
||||
@@ -97,7 +97,11 @@ fn record_row(record: &ChangeRecord) -> Result<Vec<Cell>, PipelineError> {
|
||||
])
|
||||
}
|
||||
|
||||
fn level_section(level: ChangeLevel, records: &[ChangeRecord]) -> Result<String, PipelineError> {
|
||||
fn level_section(
|
||||
level: ChangeLevel,
|
||||
records: &[ChangeRecord],
|
||||
spent: &mut usize,
|
||||
) -> Result<String, PipelineError> {
|
||||
let rows = records
|
||||
.iter()
|
||||
.filter(|record| record.change.level == level)
|
||||
@@ -113,9 +117,9 @@ fn level_section(level: ChangeLevel, records: &[ChangeRecord]) -> Result<String,
|
||||
"Références",
|
||||
"Confirmation requise",
|
||||
];
|
||||
// The rows are bounded through the records' weight; their alignment is checked here,
|
||||
// before the raw table is joined.
|
||||
assert_table_bound(&head, &rows)?;
|
||||
// The rows are bounded through the records' weight; the alignment of the three level
|
||||
// tables together is checked here, before each raw table is joined.
|
||||
assert_table_bound(&head, &rows, spent)?;
|
||||
let body = if rows.is_empty() {
|
||||
"Aucun changement de ce niveau.".to_owned()
|
||||
} else {
|
||||
@@ -192,8 +196,9 @@ pub fn render_changelog(
|
||||
comparison(before, after),
|
||||
migration(migration_stats),
|
||||
];
|
||||
let mut spent = 0;
|
||||
for level in LEVELS {
|
||||
sections.push(level_section(level, records)?);
|
||||
sections.push(level_section(level, records, &mut spent)?);
|
||||
}
|
||||
Ok(format!("{}\n", sections.join("\n\n")))
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
use serde_json::{Map, Value, json};
|
||||
|
||||
use crate::json::to_js_compact;
|
||||
|
||||
use super::app_review::render_app_review_drawing;
|
||||
use super::apply::{apply_changeset, curated_issues};
|
||||
use super::changelog::render_changelog;
|
||||
@@ -199,23 +201,77 @@ fn view_ids(document: &Value) -> Vec<String> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The review drawings' bytes, projected before any is rendered: every drawing repeats the
|
||||
/// whole cleaned drawing, two per view (the equine draft: 2 views, about 0.55 MB). Views added
|
||||
/// by a changeset multiply it (2,000 views asked for 547 MB, security gate R5.4 round 8).
|
||||
/// The review drawings' bytes, projected as an upper bound before any is rendered (the equine
|
||||
/// draft projects 1.4 MB for 0.56 MB written): every drawing repeats the whole cleaned drawing,
|
||||
/// two per view, and each annotation of a view adds its markup. Views added by a changeset
|
||||
/// multiply the drawing (2,000 views asked for 547 MB, security gate R5.4 round 8); unnamed
|
||||
/// triggers repeat the opened view's names in theirs (a 485 KB changeset wrote a 131 MB
|
||||
/// drawing, round 10).
|
||||
pub const MAX_REVIEW_DRAWINGS_BYTES: usize = 64 * 1024 * 1024;
|
||||
|
||||
/// An upper bound of what one annotation writes in a drawing: a fixed part (tags, styles,
|
||||
/// numbers the renderer adds), then its own JSON text and the longest view name, each copied
|
||||
/// at most four times (data attributes and titles of the hit box and the visible circle) and
|
||||
/// escaped at most six times longer (`"` → `"`).
|
||||
fn annotation_bytes(annotation: &Value, view_names: usize) -> Result<usize, PipelineError> {
|
||||
let text = to_js_compact(annotation).map_err(|error| fail(format!("annotation: {error}")))?;
|
||||
Ok(1024 + 24 * (text.len() + view_names))
|
||||
}
|
||||
|
||||
/// The bound of the markup a document's annotations add to one view's drawing.
|
||||
fn layer_bytes(document: &Value, view_id: &str, view_names: usize) -> Result<usize, PipelineError> {
|
||||
let annotations = document.get("annotations").and_then(Value::as_array);
|
||||
let mut total = 0usize;
|
||||
for annotation in annotations.into_iter().flatten() {
|
||||
if annotation.get("view_id").and_then(Value::as_str) == Some(view_id) {
|
||||
total = total.saturating_add(annotation_bytes(annotation, view_names)?);
|
||||
}
|
||||
}
|
||||
Ok(total)
|
||||
}
|
||||
|
||||
/// The longest JSON text of a view name, in either document.
|
||||
fn longest_view_name(documents: [&Value; 2]) -> Result<usize, PipelineError> {
|
||||
let mut longest = 0;
|
||||
for document in documents {
|
||||
let views = document.get("views").and_then(Value::as_array);
|
||||
for name in views
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|view| view.get("name"))
|
||||
{
|
||||
let text = to_js_compact(name).map_err(|error| fail(format!("view: {error}")))?;
|
||||
longest = longest.max(text.len());
|
||||
}
|
||||
}
|
||||
Ok(longest)
|
||||
}
|
||||
|
||||
/// The projected bytes of the review drawings: per view, the overlay (both documents' markers)
|
||||
/// and the application's drawing (the curated layer), each over the cleaned drawing.
|
||||
pub fn review_drawings_bytes(draft: &DraftResult) -> Result<usize, PipelineError> {
|
||||
let names = longest_view_name([&draft.baseline, &draft.document])?;
|
||||
let mut total = 0usize;
|
||||
for view_id in view_ids(&draft.document) {
|
||||
let after = layer_bytes(&draft.document, &view_id, names)?;
|
||||
let before = layer_bytes(&draft.baseline, &view_id, names)?;
|
||||
let view = draft.cleaned_svg.len().saturating_mul(2) + before + after.saturating_mul(2);
|
||||
total = total.saturating_add(view);
|
||||
}
|
||||
Ok(total)
|
||||
}
|
||||
|
||||
/// One review overlay per view (`review/annotations-<view>.svg`), then the application's
|
||||
/// drawing of each view (`review/app-<view>.svg`).
|
||||
fn review_drawings(draft: &DraftResult) -> Result<Vec<(String, String)>, PipelineError> {
|
||||
let views = view_ids(&draft.document);
|
||||
let projected = draft.cleaned_svg.len().saturating_mul(2 * views.len());
|
||||
let projected = review_drawings_bytes(draft)?;
|
||||
if projected > MAX_REVIEW_DRAWINGS_BYTES {
|
||||
return Err(fail(format!(
|
||||
"{} views would write {projected} bytes of review drawings, past the \
|
||||
{MAX_REVIEW_DRAWINGS_BYTES} bound",
|
||||
views.len()
|
||||
"the review drawings would write up to {projected} bytes, past the \
|
||||
{MAX_REVIEW_DRAWINGS_BYTES} bound"
|
||||
)));
|
||||
}
|
||||
let views = view_ids(&draft.document);
|
||||
let drawing = read_cleaned_drawing(&draft.cleaned_svg)?;
|
||||
let typed: AnatomicalSheetDocument = serde_json::from_value(draft.document.clone())
|
||||
.map_err(|error| fail(format!("curated document: {error}")))?;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
use serde::Serialize;
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use super::schema::{ChangeSummary, Op};
|
||||
use super::schema::{ChangeSummary, Op, Position};
|
||||
use super::targets::{Item, Path, Step, at_mut};
|
||||
use crate::curation::PipelineError;
|
||||
|
||||
@@ -187,15 +187,23 @@ fn parts_weight(parts: &RecordParts<'_>) -> usize {
|
||||
fn op_weight(op: &Op) -> usize {
|
||||
let carried = match op {
|
||||
Op::Set(op) => text_weight(&op.field) + value_weight(&op.value),
|
||||
Op::Add(op) => value_weight(&op.value),
|
||||
Op::Add(op) => value_weight(&op.value) + position_weight(op.position.as_ref()),
|
||||
Op::Rename(op) => text_weight(&op.id),
|
||||
Op::Move(op) => text_weight(&op.to),
|
||||
Op::Move(op) => text_weight(&op.to) + position_weight(op.position.as_ref()),
|
||||
Op::Cite(op) => op.reference_ids.iter().map(|id| text_weight(id)).sum(),
|
||||
Op::Remove(_) => 0,
|
||||
};
|
||||
64 + text_weight(op.target()) + carried
|
||||
}
|
||||
|
||||
/// The anchor an add or a move clones with its op.
|
||||
fn position_weight(position: Option<&Position>) -> usize {
|
||||
match position {
|
||||
Some(Position::After { after: id } | Position::Before { before: id }) => text_weight(id),
|
||||
Some(Position::Index(_)) | None => 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// A cloned string: its header and allocation, then its bytes.
|
||||
fn text_weight(text: &str) -> usize {
|
||||
64 + text.len()
|
||||
|
||||
@@ -48,23 +48,29 @@ pub fn cell(value: &Cell) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Refuses a table whose alignment would pass `MAX_TABLE_COLUMNS_TOTAL`, from its cells, before
|
||||
/// the raw table is joined: a cell's bytes bound its display width (an emoji, the one glyph
|
||||
/// wider than its bytes, is refused by the width table), so the projection never under-counts.
|
||||
pub fn assert_table_bound(head: &[&str], rows: &[Vec<Cell>]) -> Result<(), PipelineError> {
|
||||
/// Refuses tables whose alignment would pass `MAX_TABLE_COLUMNS_TOTAL` together (`spent` carries
|
||||
/// the projections of the report's earlier tables), from their cells, before the raw table is
|
||||
/// joined: a cell's bytes bound its display width (an emoji, the one glyph wider than its bytes,
|
||||
/// is refused by the width table), so the projection never under-counts.
|
||||
pub fn assert_table_bound(
|
||||
head: &[&str],
|
||||
rows: &[Vec<Cell>],
|
||||
spent: &mut usize,
|
||||
) -> Result<(), PipelineError> {
|
||||
let mut widths: Vec<usize> = head.iter().map(|text| text.len().max(3)).collect();
|
||||
for row in rows {
|
||||
for (width, value) in widths.iter_mut().zip(row) {
|
||||
let bytes = match value {
|
||||
Cell::Text(text) => text.len() + text.matches('|').count(),
|
||||
Cell::Number(_) => 24,
|
||||
Cell::Number(_) => 25,
|
||||
Cell::Null => 1,
|
||||
};
|
||||
*width = (*width).max(bytes);
|
||||
}
|
||||
}
|
||||
let row_width = widths.iter().sum::<usize>() + 3 * widths.len() + 1;
|
||||
if row_width.saturating_mul(rows.len() + 2) > MAX_TABLE_COLUMNS_TOTAL {
|
||||
*spent = spent.saturating_add(row_width.saturating_mul(rows.len() + 2));
|
||||
if *spent > MAX_TABLE_COLUMNS_TOTAL {
|
||||
return Err(PipelineError::Guard(format!(
|
||||
"an aligned table of {} rows × {row_width} columns exceeds the {MAX_TABLE_COLUMNS_TOTAL} bound",
|
||||
rows.len() + 2
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
//! punctuation of `PUNCTUATION`, an underscore between two ASCII letters or digits and not
|
||||
//! glued to a URL, a backslash before `"` or `|` (a JSON quote, the cell escape), `**word**`
|
||||
//! (one run of letters between spaces or line edges, the import report's form), no inline
|
||||
//! construct (`rewritten_construct`). Inside code spans (the generated ids and targets):
|
||||
//! anything but a carriage return or a tab, never empty, no outer space; an authored text holds
|
||||
//! construct (`rewritten_construct`). Inside code spans (the generated ids, targets, field
|
||||
//! names and file paths): only `[A-Za-z0-9_:/. -]`, never empty, no outer space; an authored text holds
|
||||
//! no backtick (`assert_authored`), and a plain underscore is never followed by another one on its
|
||||
//! line.
|
||||
|
||||
|
||||
@@ -511,9 +511,38 @@ fn review_drawings_past_their_bound_are_refused_before_rendering() {
|
||||
}
|
||||
let error = render_draft_artifacts(&draft, &result.anomalies).unwrap_err();
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains("bytes of review drawings, past the"),
|
||||
error.to_string().contains("past the 67108864 bound"),
|
||||
"{error}"
|
||||
);
|
||||
}
|
||||
|
||||
/// An unnamed trigger writes the opened view's names in its markup: many of them opening a
|
||||
/// long-named view are refused before rendering too (security gate R5.4 round 10: a 485 KB
|
||||
/// changeset wrote a 131 MB drawing). The equine draft stays far below the bound.
|
||||
#[test]
|
||||
fn unnamed_triggers_repeating_a_long_view_name_are_refused_before_rendering() {
|
||||
use faunosteo_core::curation::draft::pipeline::{
|
||||
MAX_REVIEW_DRAWINGS_BYTES, review_drawings_bytes,
|
||||
};
|
||||
let (result, mut draft) = equine();
|
||||
let equine = review_drawings_bytes(&draft).unwrap();
|
||||
println!("equine review drawings projected at {equine} bytes");
|
||||
assert!(equine * 4 < MAX_REVIEW_DRAWINGS_BYTES, "{equine}");
|
||||
draft.document["views"][1]["name"]["fr"] = Value::from("t".repeat(32_768));
|
||||
let annotations = draft.document["annotations"].as_array_mut().unwrap();
|
||||
let trigger = annotations
|
||||
.iter()
|
||||
.find(|a| a["kind"] == "detail_trigger")
|
||||
.unwrap()
|
||||
.clone();
|
||||
for index in 0..1_000 {
|
||||
let mut copy = trigger.clone();
|
||||
copy["id"] = Value::from(format!("trigger-{index}"));
|
||||
annotations.push(copy);
|
||||
}
|
||||
let error = render_draft_artifacts(&draft, &result.anomalies).unwrap_err();
|
||||
assert!(
|
||||
error.to_string().contains("past the 67108864 bound"),
|
||||
"{error}"
|
||||
);
|
||||
}
|
||||
@@ -3101,7 +3101,7 @@ Owner go « Validation R5.3 et autorisation conditionnelle R5.4 » (2026-10-23),
|
||||
fresh verification of the final R5.3 state: met on c6e0d85 (CONFORME 13/13, security PASS with
|
||||
LOWs only, §11.12). Contract `.claude/tasks/contracts/2026-10-23-rust-r5-review.md`.
|
||||
|
||||
`crates/core/src/curation/draft` gains 1,477 lines (4,385 in all), plus `curation/report_guard.rs` (258):
|
||||
`crates/core/src/curation/draft` gains 1,692 lines (4,600 in all), plus `curation/report_guard.rs` (258):
|
||||
|
||||
| Module | Ports |
|
||||
|---|---|
|
||||
@@ -3116,7 +3116,7 @@ LOWs only, §11.12). Contract `.claude/tasks/contracts/2026-10-23-rust-r5-review
|
||||
| `pipeline.rs` | `render_draft_artifacts` complete, in the TypeScript order: document, assets, sheet-ref, migration map, the overlays and the application's drawings per view, CHANGELOG, REVIEW-REPORT, seed SQL |
|
||||
| `bin/import_equine.rs` | `--check` compares the 6 + 12 files with explicit criteria (byte identity; the application's drawings may fall back on parsed trees under the declared rule, printed as `declared:`); a file missing, not produced or different fails; the pending list and its `shortcut:` are gone; `--out` writes the 18 files |
|
||||
|
||||
Parity, every expectation written by the TypeScript (`tests/curation_review.rs`, 9 tests):
|
||||
Parity, every expectation written by the TypeScript (`tests/curation_review.rs`, 11 tests):
|
||||
|
||||
- `CHANGELOG.md` (1,114,533 bytes) and `REVIEW-REPORT.md` of the committed draft byte for byte;
|
||||
their raw texts equal the ledger's pre-Prettier digests, the aligned texts its digests;
|
||||
@@ -3165,7 +3165,7 @@ between two ASCII letters or digits and not glued to a URL (`http://`, `https://
|
||||
backslash before `"` or `|` (a JSON quote, the cell escape), `**word**` with one run of letters
|
||||
between spaces or line edges (the import report's form), and no inline construct (an inline link,
|
||||
image or reference `](`, `][`; an image reference `![`; a `[[` before a space with a `]]` after
|
||||
it, or a `]]` after a space with a `[[` before it; `<` before a letter, `/`, `!` or `?`: an HTML
|
||||
it, or a `]]` after a space with a `[[` before it; `<` before an ASCII letter, `/`, `!` or `?`: an HTML
|
||||
tag or an autolink; a character reference `&name;`, `&#n;`; a liquid bracket `{%` or `%}`); no plain underscore followed later on
|
||||
its line by one that can close an emphasis (inside a later code span, before anything but an ASCII
|
||||
letter or digit: Prettier's parser paired `to_do … \`ref_\`` across the span); an authored text
|
||||
@@ -3203,9 +3203,9 @@ pass the guard unchanged.
|
||||
|---|---|---|
|
||||
| authored text outside the allowlist: Markdown Prettier rewrites (`*x*`, `_x`, `x_**a**`, `**a****b**`, `Voir_https://…`, `a b`, a non-ASCII space, a tab, a line break in a list item, `` `` ``, `a\|b`, `[a](<b>)`, `[[ a ]]`, `*`…), the constructs refused whole (links, HTML tags, autolinks, character references) and any character outside the admitted set (pictographs, symbols, combining marks without the Alphabetic property; an alphabetic mark such as U+0345 is a letter and Prettier aligns it alike) | written, then rewritten by Prettier (escapes, `_emphasis_`, collapsed spaces, indented continuation lines, normalised links; a row with an extra cell), or kept | refused (`UnsupportedMarkdown`), even where Prettier would have kept the text |
|
||||
| a pictograph in a table cell (an emoji, and ©, ®, ™, ✓, ★, ⚠ and the other characters `text::is_emoji_candidate` lists) | measured with Prettier's tables | refused (`UnsupportedWidth`, R5.2): the set is wider than the emoji, the refusal stays loud |
|
||||
| an aligned report table past 32 Mi display columns in all (rows × padded row width; the equine CHANGELOG's widest table is about 0.5 MB): one long authored cell pads every row of its level, so an 80 KB rationale over 14,000 records asked for 1 GB (security gate R5.4 round 6) | Prettier aligned it (the same amplification) | refused (`Guard`): the CHANGELOG's tables are projected from their cells (bytes bound the display width) before the raw table is joined (test `a_changelog_whose_alignment_would_explode_is_refused_before_it_is_built`, through the pipeline), every other table in the aligner before any padded row is built (test `an_aligned_table_past_the_bound_is_refused_before_it_is_built`), import report included |
|
||||
| records weighing more than 16 Mi units in all (`records::record_weight`, about the bytes in memory: 64 per JSON value and per string, plus one per byte of text, for the values, the change and the op, which each record clones; the equine records weigh 1,965,944): a rename or a remove records the whole item and one op, or the B/C marking, records once per item it reaches, so 400 renames of a 5,000-child item asked for 4.3 GB (round 7), a level B add of 10,000 children with a 128 KiB rationale 1.37 GB inside one marking, a 64 KiB value set over a subtree 2.0 GB (round 8), 200,000 one-character reference ids cloned into each record 948 MB at one unit per byte (round 9) | recorded (the same copies) | refused at the record that passes the bound, charged before the change and the op are cloned into it (`records::charge`, tests `the_records_cannot_outgrow_their_bound`, `the_records_bound_holds_inside_one_op_and_the_marking`); the raw report rows, built from the records, are bounded with them; the 200,000-value document bound now holds the baseline (test from a padded baseline) |
|
||||
| review drawings past 64 MiB in all, projected before any is rendered (two per view, each repeating the cleaned drawing; the equine draft writes about 0.55 MB): 2,000 views asked for 547 MB (security gate R5.4 round 8) | written | refused before rendering (`pipeline::MAX_REVIEW_DRAWINGS_BYTES`, test `review_drawings_past_their_bound_are_refused_before_rendering`) |
|
||||
| aligned report tables past 32 Mi display columns in all (rows × padded row width, the CHANGELOG's three level tables summed; the equine CHANGELOG's widest table is about 0.5 MB): one long authored cell pads every row of its level, so an 80 KB rationale over 14,000 records asked for 1 GB (security gate R5.4 round 6) | Prettier aligned it (the same amplification) | refused (`Guard`): the CHANGELOG's tables are projected from their cells (bytes bound the display width) before the raw table is joined (test `a_changelog_whose_alignment_would_explode_is_refused_before_it_is_built`, through the pipeline), every other table in the aligner before any padded row is built (test `an_aligned_table_past_the_bound_is_refused_before_it_is_built`), import report included |
|
||||
| records weighing more than 16 Mi units in all (`records::record_weight`, about the bytes in memory: 64 per JSON value and per string, plus one per byte of text, for the values, the change and the op, which each record clones; the equine records weigh 1,966,163; an add or a move also clones its position anchor): a rename or a remove records the whole item and one op, or the B/C marking, records once per item it reaches, so 400 renames of a 5,000-child item asked for 4.3 GB (round 7), a level B add of 10,000 children with a 128 KiB rationale 1.37 GB inside one marking, a 64 KiB value set over a subtree 2.0 GB (round 8), 200,000 one-character reference ids cloned into each record 948 MB at one unit per byte (round 9) | recorded (the same copies) | refused at the record that passes the bound, charged before the change and the op are cloned into it (`records::charge`, tests `the_records_cannot_outgrow_their_bound`, `the_records_bound_holds_inside_one_op_and_the_marking`); the raw report rows, built from the records, are bounded with them; the 200,000-value document bound now holds the baseline (test from a padded baseline) |
|
||||
| review drawings past 64 MiB in all, projected as an upper bound before any is rendered (`pipeline::review_drawings_bytes`: per view, the cleaned drawing twice, plus for each annotation of the view in the overlay's two documents and in the application's drawing 1,024 bytes and 24 times its JSON text and the longest view name, four copies escaped up to six times longer; the equine draft projects 1,390,428 bytes for about 0.56 MB written): 2,000 views asked for 547 MB (security gate R5.4 round 8), unnamed triggers repeating a long opened view's names 131 MB from a 485 KB changeset (round 10) | written | refused before rendering (`pipeline::MAX_REVIEW_DRAWINGS_BYTES`, tests `review_drawings_past_their_bound_are_refused_before_rendering`, `unnamed_triggers_repeating_a_long_view_name_are_refused_before_rendering`) |
|
||||
| an id an `add` writes (the item's, and those nested in its `children` or `categories`) or a `rename` id that is not a stable id (a region code for a region), or a field segment outside `[A-Za-z0-9_-]` (a control character, NUL included, a backtick, a `]`, a space, a non-ASCII letter) | accepted when a later op removed or renamed the item: the raw id stayed in the records and reached the reports' code spans (a line break there forged a section, security gate R5.4 round 2) | refused at the op, the check the final document applies anyway (test `ids_and_field_segments_that_could_forge_report_structure_are_refused`) |
|
||||
| a label, id or path holding a code point XML 1.0 refuses, or a carriage return, in a review drawing | written (a non-well-formed file; a raw CR read back as a line feed) | refused: the drawing is not written |
|
||||
|
||||
@@ -3220,8 +3220,8 @@ holds (a 100,000-level file is refused, never a stack overflow). The overlay pri
|
||||
that overflowed as `Infinity`, as `String(number)` did. The renderers are indexed (citation
|
||||
counts in one walk, previous markers and kept ids hashed, subjects grouped per change).
|
||||
|
||||
Tests: `cargo test -p faunosteo-core --features curation` (review 9, Markdown 1, draft 16,
|
||||
importer 5, binary 3, formatting 6, plus the crate's suites); anatomy 144 (two generators added).
|
||||
Tests: `cargo test -p faunosteo-core --features curation` (review 11, Markdown 2, draft 18,
|
||||
importer 5, binary 3, formatting 7, plus the crate's suites); anatomy 144 (two generators added).
|
||||
|
||||
### 11.15 Checkpoint R5.4
|
||||
|
||||
|
||||
Reference in new issue
Block a user