fix(domain): V1-2.2 second review round, linear walks, bounds, CSS loaders

Verifier ECARTS(3) and security PASS on 8294d54: one indexed walk per
view chain in sheet.edit, a set for referenced drawings, released
preview parses, xml:base and CSS loaders refused, fail-closed PI scan,
PI drawings rejected by the preview, the builder naming its cap.
This commit is contained in:
bchanot committed 2026-10-29 13:58:32 +01:00
1 parent 8294d5471c
commit ca31b787b6
13 files changed
+201 -36

No files matched your search

+40 -6
View File
@@ -34,7 +34,6 @@ use super::schema::{
FindingNode, FindingZone, LocalizedOptionalText, LocalizedText, Reference, ReviewStatus,
SheetView, VertebralRegion, ViewBox,
};
use crate::anatomy::compose::asset_id_of_view;
use crate::domain::archive::SnapshotCaps;
/// The sheet's own texts, set as one element.
@@ -782,16 +781,51 @@ fn children_mut<'a>(
fn view_drawings(
doc: &AnatomicalSheetDocument,
) -> HashMap<String, (Option<String>, Option<ViewBox>)> {
let mut out = HashMap::new();
let mut first: HashMap<&str, &SheetView> = HashMap::new();
for view in &doc.views {
out.entry(view.id().to_owned()).or_insert_with(|| {
let asset = asset_id_of_view(doc, view.id()).map(str::to_owned);
(asset, view.view_box().cloned())
});
first.entry(view.id()).or_insert(view);
}
let mut assets: HashMap<&str, Option<String>> = HashMap::new();
let mut out = HashMap::new();
for (&id, view) in &first {
let asset = drawn_asset(id, &first, &mut assets);
out.insert(id.to_owned(), (asset, view.view_box().cloned()));
}
out
}
/// The drawing a view shows: its own, else the first up its parent chain (as
/// `asset_id_of_view`), each chain walked once thanks to `known`; a cycle draws nothing.
fn drawn_asset<'a>(
id: &'a str,
views: &HashMap<&'a str, &'a SheetView>,
known: &mut HashMap<&'a str, Option<String>>,
) -> Option<String> {
let mut chain: Vec<&str> = Vec::new();
let mut current = Some(id);
let found = loop {
let Some(here) = current else { break None };
if let Some(done) = known.get(here) {
break done.clone();
}
if chain.contains(&here) {
break None;
}
chain.push(here);
let Some(view) = views.get(here) else {
break None;
};
if let Some(asset) = view.svg_asset_id() {
break Some(asset.to_owned());
}
current = view.parent_view_id();
};
for link in chain {
known.insert(link, found.clone());
}
found
}
/// Annotations of a view whose drawing or crop changed turn `to_confirm` (§6.6).
fn reconfirm_redrawn_views(
doc: &mut AnatomicalSheetDocument,
+25 -2
View File
@@ -25,6 +25,7 @@ use super::report::{SheetReport, referenced_asset_ids, sheet_report};
use super::review::DigestError;
use super::schema::{AnatomicalSheetDocument, LocalizedText};
use super::verdict::{read_document, sha256_hex};
use crate::anatomy::svg::processing_instructions;
use crate::domain::archive::SnapshotCaps;
use crate::domain::js;
@@ -112,6 +113,14 @@ impl PreviewFailure {
/// uploads of one editing session (each one at most 2 MiB, refused above).
pub const MAX_HELD_DRAWINGS: usize = 16;
/// A drawing as the verdict would read it: a processing instruction refuses it here too.
fn preview_drawing(text: &str) -> Drawing {
if !processing_instructions(text).is_empty() {
return Err("processing_instruction".to_owned());
}
read_drawing(text)
}
struct Asset {
sha256: String,
bytes: u64,
@@ -185,17 +194,26 @@ impl PreviewSheet {
if !self.drawings.contains_key(&drawing.sha256) {
self.reads += 1;
let read = std::str::from_utf8(&drawing.bytes)
.map_or_else(|_| Err("malformed".to_owned()), read_drawing);
.map_or_else(|_| Err("malformed".to_owned()), preview_drawing);
self.drawings.insert(drawing.sha256.clone(), read);
}
let asset = Asset {
sha256: drawing.sha256,
bytes: drawing.bytes.len() as u64,
};
self.assets.insert(drawing.asset_id, asset);
if let Some(replaced) = self.assets.insert(drawing.asset_id, asset) {
self.release(&replaced.sha256);
}
Ok(())
}
/// Drops a parse no asset holds any more, so re-adding an asset never accumulates them.
fn release(&mut self, sha256: &str) {
if !self.assets.values().any(|a| a.sha256 == sha256) {
self.drawings.remove(sha256);
}
}
/// A draft's document after an edit; the drawings are kept as read. On a refusal the
/// previous document stays.
pub fn replace_document(&mut self, text: &str) -> Result<(), PreviewFailure> {
@@ -228,6 +246,11 @@ impl PreviewSheet {
self.drawings.get(&asset.sha256)
}
/// Parsed drawings held now (one per sha256 still referenced by an asset).
pub fn held_parses(&self) -> usize {
self.drawings.len()
}
/// How many times a drawing was read (each sha256 once).
pub fn drawing_reads(&self) -> usize {
self.reads
+7 -7
View File
@@ -71,11 +71,11 @@ fn geometry_of(annotation: &Annotation) -> Option<&super::schema::Geometry> {
/// The distinct drawings the views reference, in view order.
pub fn referenced_asset_ids(document: &AnatomicalSheetDocument) -> Vec<&str> {
let mut ids: Vec<&str> = Vec::new();
for id in document.views.iter().filter_map(|v| v.svg_asset_id()) {
if !ids.contains(&id) {
ids.push(id);
}
}
ids
let mut seen = std::collections::HashSet::new();
document
.views
.iter()
.filter_map(|v| v.svg_asset_id())
.filter(|id| seen.insert(*id))
.collect()
}