fix(domain): OD-3 value count runs past the depth cap; the rescue-copy guard covers the archive text
Security gate finding (R4.2): prescan stopped counting once the depth exceeded 64, so a 16 MiB rescue copy nested 65 deep passed the value budget with 66 values and built its 792 MiB tree. The count now runs to the end (the depth verdict unchanged, the PDF probe unchanged); the class is in the budget suite (48 MiB, refused) and pinned in cargo.
This commit is contained in:
1 parent
1695fbb408
commit
593893a7c2
4 files changed
+31
-12
No files matched your search
@@ -316,8 +316,10 @@ fn versioned(kind: &'static str, found: Option<f64>) -> Failure {
|
||||
fn draft_restore(sheet: &LoadedSheet, input: &str) -> Outcome {
|
||||
let input: DraftRestoreInput = parse_input(input)?;
|
||||
// OD-3: a token-dense text is refused before the parser allocates its tree; the caller
|
||||
// sets the text aside verbatim, as for any unreadable draft (`invalid`).
|
||||
if prescan(input.draft.as_bytes()).values > MAX_JSON_VALUES {
|
||||
// sets the text aside verbatim, as for any unreadable draft (`invalid`). The archive is
|
||||
// checked too: a stored one was accepted under the budget, so only a crafted one fails.
|
||||
let texts = [Some(input.draft.as_str()), input.archive.as_deref()];
|
||||
if texts.into_iter().flatten().any(over_value_budget) {
|
||||
return Err(Failure::new("invalid", "json value budget exceeded"));
|
||||
}
|
||||
session::restore_draft(sheet, &input.draft, input.archive.as_deref())
|
||||
@@ -330,6 +332,10 @@ fn draft_restore(sheet: &LoadedSheet, input: &str) -> Outcome {
|
||||
.and_then(|restore| to_value(&restore))
|
||||
}
|
||||
|
||||
fn over_value_budget(text: &str) -> bool {
|
||||
prescan(text.as_bytes()).values > MAX_JSON_VALUES
|
||||
}
|
||||
|
||||
/// The input is the attachment's JSON as the byte scan read it (any shape).
|
||||
fn archive_import(sheet: &LoadedSheet, input: &str) -> Outcome {
|
||||
session::import_archive(sheet, input)
|
||||
|
||||
Reference in new issue
Block a user