From 10dfb8b2610a0a9996f0b2879dec69402acef92d Mon Sep 17 00:00:00 2001 From: Rahul Date: Tue, 27 Oct 2026 12:40:07 +0530 Subject: [PATCH] fix(format): cap a compressed file's JSON at 256 MB on wasm32 (#3587) MAX_JSON was 1 GiB on every target, but on wasm32 the 4 GiB address space also holds the document the JSON deserializes into, several times its size. The cap is now a quarter of the native one there, mirroring MAX_BLOBS, and Unpacked::within makes the cap exercisable wherever a test runs. Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com> --- crates/format/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/format/src/lib.rs b/crates/format/src/lib.rs index 292385305..798fcf312 100644 --- a/crates/format/src/lib.rs +++ b/crates/format/src/lib.rs @@ -66,8 +66,10 @@ pub const EXTENSION: &str = "vectorcraft"; pub const LEGACY_EXTENSION: &str = "drawcraft"; /// Most bytes the JSON of a compressed file may unpack to (a guard against decompression bombs, /// as are [`MAX_BLOB`] and [`MAX_BLOBS`]). A compressed save refuses a document past any of them, -/// so every file VectorCraft writes reads back. -pub const MAX_JSON: u64 = 1 << 30; +/// so every file VectorCraft writes reads back. On wasm32 the cap is a quarter of the native +/// one: the JSON is deserialized into a document several times its size, and the 4 GiB address +/// space also holds the file, the JSON, the document and the app (#3587). +pub const MAX_JSON: u64 = if cfg!(target_arch = "wasm32") { 256 << 20 } else { 1 << 30 }; /// Most bytes one entry of the data after the JSON (an image, a placed document, the PDF, a /// profile) may have in a compressed file. pub const MAX_BLOB: u64 = 1 << 30;