diff --git a/.claude/rules/sheet-model.md b/.claude/rules/sheet-model.md index 6ceff042..e187da71 100644 --- a/.claude/rules/sheet-model.md +++ b/.claude/rules/sheet-model.md @@ -27,7 +27,8 @@ paths: ["crates/core/src/domain/sheet/**", "docs/development/ANATOMICAL_SHEET_MO - Omitted `review_status` means `inherited` (`#[serde(default)]`): any check on statuses treats an absent value as `inherited`. - Since V1-2.2 the core also holds the review model (`review.rs`: groups, digests, `coverable`, change list), the server - verdict (`verdict.rs`, the shape the M5 SQL reads; never exported to the browser), the document measure (`size.rs`: + verdict (`verdict.rs`, the shape the M5 SQL reads; the function is never exported to the browser, only its TypeScript type for the + review screen), the document measure (`size.rs`: PostgreSQL's `jsonb` text, never `JSON.stringify`), `PreviewSheet` and the editor's commands (`edit.rs`, the §6.6 marking rules). A change to the SVG reader, the rules, the caps, the fingerprint or the digests is a core change (contract §6.4: the release withdraws open rounds). RUST.md §12. diff --git a/crates/core/src/anatomy/svg/clean.rs b/crates/core/src/anatomy/svg/clean.rs index 7b981e0f..f116f623 100644 --- a/crates/core/src/anatomy/svg/clean.rs +++ b/crates/core/src/anatomy/svg/clean.rs @@ -2,8 +2,9 @@ //! the core reader before anything is stored, and gets one of three answers. //! //! - rejected: a hard rejection of the reader (with its reason), a text that is not UTF-8 -//! (`malformed`), or any removal of active or external content (`svg_active_content`, the -//! names in `active`); no cleaning is offered; +//! (`malformed`), or any removal of active or external content, or a processing +//! instruction (`svg_active_content`, the names in `active`, a PI as `?`); no +//! cleaning is offered; //! - cleanable: only other removals (editor metadata and namespaces, `data-*`, `"#; diff --git a/crates/wasm/src/lib.rs b/crates/wasm/src/lib.rs index b1fb4532..7fe1f45a 100644 --- a/crates/wasm/src/lib.rs +++ b/crates/wasm/src/lib.rs @@ -3,8 +3,9 @@ //! and `packages/core-wasm/pkg-proofs` (with the trap exports, tests only); loaded lazily by //! the application behind the sheet and import paths (`packages/core-wasm/src/runtime.ts`). +use faunosteo_core::domain::archive::SnapshotCaps; use faunosteo_core::domain::sheet::LoadedSheet; -use faunosteo_core::domain::sheet::preview::PreviewDrawing; +use faunosteo_core::domain::sheet::preview::{MAX_HELD_DRAWINGS, PreviewDrawing}; use faunosteo_core::pdf::read::MAX_PDF_BYTES; use wasm_bindgen::prelude::{JsError, wasm_bindgen}; @@ -71,6 +72,8 @@ impl SheetHandle { #[wasm_bindgen] pub struct PreviewBuilder { drawings: Vec, + /// A drawing was refused: the build answers `caps`. + refused: bool, } #[wasm_bindgen] @@ -79,21 +82,33 @@ impl PreviewBuilder { pub fn new() -> PreviewBuilder { PreviewBuilder { drawings: Vec::new(), + refused: false, } } - pub fn add_drawing(&mut self, asset_id: &str, sha256: &str, bytes: &[u8]) { + /// `false` (nothing kept) past the preview's drawing count or a drawing over 2 MiB; the + /// build then refuses with `caps` as the core does. + pub fn add_drawing(&mut self, asset_id: &str, sha256: &str, bytes: &[u8]) -> bool { + let full = self.drawings.len() >= MAX_HELD_DRAWINGS; + if full || bytes.len() > SnapshotCaps::ASSET_BYTES { + self.refused = true; + return false; + } self.drawings.push(PreviewDrawing { asset_id: asset_id.to_owned(), sha256: sha256.to_owned(), bytes: bytes.to_vec(), }); + true } /// Consumes the builder; throws an `Error` worded `: ` (`invalid_document`, /// `drawing_missing`, `drawing_hash_mismatch`, `fingerprint_mismatch`, `caps`, or /// `invalid_shape` / `invalid_json` for the input). pub fn build(self, input: &str) -> Result { + if self.refused { + return Err(JsError::new("caps: drawings")); + } faunosteo_core::facade::load_preview(input, self.drawings) .map(|sheet| PreviewSheet { sheet }) .map_err(|failure| JsError::new(&format!("{}: {}", failure.kind, failure.detail))) diff --git a/docs/development/RUST.md b/docs/development/RUST.md index e0ffae18..8a0f2949 100644 --- a/docs/development/RUST.md +++ b/docs/development/RUST.md @@ -3874,8 +3874,9 @@ Free (`call`): `sheet.edit` `{document, command}` → `{document}`, failures `un budget); `sheet.dependents` `{document, key}` → `{dependents: [{element, relation}]}`. Wasm classes: `PreviewBuilder` (`add_drawing(assetId, sha256, bytes)`, `build(PreviewInput JSON)` throwing `: `: `invalid_document`, `drawing_missing`, `drawing_hash_mismatch`, `fingerprint_mismatch`, `caps`), `PreviewSheet` (`call`: `preview.state`, -`view.canvas`; `replace_document`, `add_drawing`: `{"ok":true}` or `invalid_document`, `drawing_hash_mismatch`, -`read_only`); the function `clean_svg(bytes)` (`SvgCleaning`). `view.canvas` is one composition for `LoadedSheet` and +`view.canvas`; `replace_document`, `add_drawing`: `{"ok":true,"value":null}` or `invalid_document`, +`drawing_hash_mismatch`, `caps`, `read_only`); a preview holds at most 16 drawings of at most 2 MiB each +(`MAX_HELD_DRAWINGS`; the builder's `add_drawing` answers `false` past them and its build throws `caps: drawings`); the function `clean_svg(bytes)` (`SvgCleaning`). `view.canvas` is one composition for `LoadedSheet` and `PreviewSheet` (`ops::canvas_of`). The runtime (`CoreRuntime`) does not manage preview handles yet: their poison and recovery come with their first page (V1-2.5). ts-rs: 31 new type files, `types/index.ts` 126 entries. @@ -3883,12 +3884,19 @@ recovery come with their first page (V1-2.5). ts-rs: 31 new type files, `types/i 1. The sanitiser keeps, removes and refuses exactly as before (R3 oracles O4/O5 green); its walk also lists, in `active`, each removal that carried a script, an embedded document or image (`image`, `feImage`, `foreignObject`, - `iframe`, `object`, `embed`, media), animation, a link (`a`), an event handler (`on*`), a reference outside the - document (`href`, `url(…)`), `@import`, `javascript:`, `expression(`, `image-set(`, `behavior:`, or a backslash. A - `