fix(worker): V1-2.3 hostile corpus through verify, verdict and memory caps aligned
This commit is contained in:
1 parent
7043d39ae0
commit
6aa85fe7e4
7 files changed
+67
-10
No files matched your search
@@ -201,8 +201,14 @@ fn chain_reviewed(levels: usize) -> Value {
|
||||
/// The framed input of `document` drawn on `SHEET_DRAWING`, the document also as its base
|
||||
/// (the base path is traced too); empty on a framing error.
|
||||
pub fn sheet_frame(document: &Value) -> Vec<u8> {
|
||||
sheet_frame_on(document, SHEET_DRAWING.as_bytes())
|
||||
}
|
||||
|
||||
/// The same framed input with `drawing` as the main view's drawing, its row matching its
|
||||
/// bytes (size and sha256), so the core reads it.
|
||||
pub fn sheet_frame_on(document: &Value, drawing: &[u8]) -> Vec<u8> {
|
||||
let text = document.to_string();
|
||||
let sha256 = sha256_hex(SHEET_DRAWING.as_bytes());
|
||||
let sha256 = sha256_hex(drawing);
|
||||
let input = VerdictInput {
|
||||
binding: sheet_binding(),
|
||||
document: &text,
|
||||
@@ -210,8 +216,8 @@ pub fn sheet_frame(document: &Value) -> Vec<u8> {
|
||||
drawings: vec![VerdictDrawing {
|
||||
asset_id: SHEET_ASSET,
|
||||
sha256: &sha256,
|
||||
byte_size: SHEET_DRAWING.len() as u64,
|
||||
bytes: Some(SHEET_DRAWING.as_bytes()),
|
||||
byte_size: drawing.len() as u64,
|
||||
bytes: Some(drawing),
|
||||
}],
|
||||
};
|
||||
verify_frame::encode(&input).unwrap_or_default()
|
||||
|
||||
@@ -34,8 +34,10 @@ pub const MIN_LIBWEBP_VERSION: (u8, u8, u8) = (1, 6, 0);
|
||||
pub const VERIFY_MAX_INPUT_BYTES: usize = 12 * 1024 * 1024;
|
||||
/// Largest frame header (ids and drawing rows, a few KiB in practice).
|
||||
pub const VERIFY_MAX_HEADER_BYTES: usize = 64 * 1024;
|
||||
/// Largest verdict the parent reads (= SQL `sheet_verification_max_verdict_bytes`).
|
||||
pub const VERIFY_MAX_OUTPUT_BYTES: usize = 4 * 1024 * 1024;
|
||||
/// Largest verdict the parent reads: below SQL `sheet_verification_max_verdict_bytes` (4 MiB,
|
||||
/// measured on `jsonb::text`, whose separators make the same verdict longer than the compact
|
||||
/// child output), so a verdict the child may write is one SQL measures within its cap.
|
||||
pub const VERIFY_MAX_OUTPUT_BYTES: usize = 3 * 1024 * 1024;
|
||||
/// Hard address-space cap of the `verify` child (`RLIMIT_AS`).
|
||||
pub const VERIFY_ADDRESS_SPACE_BYTES: u64 = 1024 * 1024 * 1024;
|
||||
/// CPU-time cap of the `verify` child (`RLIMIT_CPU`, seconds).
|
||||
|
||||
@@ -252,6 +252,34 @@ fn a_sheet_at_every_cap_is_verified_within_the_limits() {
|
||||
);
|
||||
}
|
||||
|
||||
/// The core's hostile SVG corpus as the drawing of a submitted sheet: each one is judged by
|
||||
/// the core inside the full sandbox (an integrity failure), never a crash or a signal.
|
||||
#[test]
|
||||
fn the_hostile_svg_corpus_fails_verification_inside_the_sandbox() {
|
||||
let dir = concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/../core/tests/fixtures/svg/hostile"
|
||||
);
|
||||
let mut seen = 0;
|
||||
for entry in std::fs::read_dir(dir).unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
let drawing = std::fs::read(&path).unwrap();
|
||||
let verdict = expect_verdict(&fixtures::sheet_frame_on(
|
||||
&fixtures::sheet_document(),
|
||||
&drawing,
|
||||
));
|
||||
let code = verdict["failure_code"].as_str().unwrap_or_default();
|
||||
assert_eq!(verdict["outcome"], "failed", "{}", path.display());
|
||||
assert!(
|
||||
code.starts_with("verification.integrity.svg_"),
|
||||
"{}: {code}",
|
||||
path.display()
|
||||
);
|
||||
seen += 1;
|
||||
}
|
||||
assert!(seen >= 40, "hostile corpus read: {seen} files");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_verify_child_refuses_a_non_empty_environment() {
|
||||
let status = Command::new(env!("CARGO_BIN_EXE_faunosteo-worker"))
|
||||
|
||||
Reference in new issue
Block a user