From 570512674e1f8c3116f562b2297332e0a1e5941f Mon Sep 17 00:00:00 2001 From: Adam Bratschi-Kaye Date: Wed, 31 Jan 2024 14:18:22 +0000 Subject: [PATCH] fix(RUN-896): Raise unzipped Wasm limit --- rs/embedders/src/wasm_utils/decoding.rs | 6 ++++-- rs/embedders/tests/compressed/zeros.gz | Bin 32585 -> 102807 bytes rs/embedders/tests/misc_tests.rs | 17 +++++++++-------- .../system_state/wasm_chunk_store.rs | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/rs/embedders/src/wasm_utils/decoding.rs b/rs/embedders/src/wasm_utils/decoding.rs index 08354445b6b..f4810cd65e0 100644 --- a/rs/embedders/src/wasm_utils/decoding.rs +++ b/rs/embedders/src/wasm_utils/decoding.rs @@ -1,9 +1,11 @@ +use ic_replicated_state::canister_state::system_state::wasm_chunk_store; +use ic_types::NumBytes; use ic_wasm_types::{BinaryEncodedWasm, WasmValidationError}; use std::io::Read; use std::sync::Arc; /// Maximum size of a WebAssembly module. -pub const MAX_WASM_MODULE_SIZE_BYTES: usize = 30 * 1024 * 1024; +pub const MAX_WASM_MODULE_SIZE_BYTES: NumBytes = wasm_chunk_store::DEFAULT_MAX_SIZE; fn make_module_too_large_error() -> WasmValidationError { WasmValidationError::DecodingError(format!( @@ -72,7 +74,7 @@ pub fn decoded_wasm_size(module_bytes: &[u8]) -> Result>) -> Result { let module_bytes = module.as_slice(); let (encoding, uncompressed_size) = wasm_encoding_and_size(module_bytes)?; - if uncompressed_size > MAX_WASM_MODULE_SIZE_BYTES { + if uncompressed_size as u64 > MAX_WASM_MODULE_SIZE_BYTES.get() { return Err(make_module_too_large_error()); } diff --git a/rs/embedders/tests/compressed/zeros.gz b/rs/embedders/tests/compressed/zeros.gz index e85fa269bbdc35b241d378be2acd0d6b1ac2246f..df65449dd6a03b0fd685c08d571d20765cbcf6cf 100644 GIT binary patch delta 170 zcmX^4k8%29whj6Tysfqt0t_JVsXmuwv!TK#`N<9nynLeH9yox7PyF917y=h(ys=qA mLEM45x~6`6Faczj!-fCX!`wG2J`&(Mz{(dwBY|Q}01dGVJ^%m! diff --git a/rs/embedders/tests/misc_tests.rs b/rs/embedders/tests/misc_tests.rs index a236bb2b0b6..9487c769d13 100644 --- a/rs/embedders/tests/misc_tests.rs +++ b/rs/embedders/tests/misc_tests.rs @@ -131,21 +131,22 @@ fn compressed_test_contents(name: &str) -> Vec { #[test] #[should_panic(expected = "too large")] fn test_decode_large_compressed_module() { - // Try decoding 12MB of zeros - decode_wasm(Arc::new(compressed_test_contents("zeros.gz"))).unwrap(); -} - -#[test] -#[should_panic(expected = "specified uncompressed size 100 does not match extracted size 101")] -fn test_decode_large_compressed_module_with_tweaked_size() { + // Try decoding 101MB of zeros + // // We also tested decoding with a much larger file. // To save space and CI time, we do not include the larger archive file and // do not generate it in the test. To reproduce the test, execute the following // command: // - // dd if=/dev/zero of=/dev/stdout bs=1048576 count=10240 | gzip -9 > zeroes.gz + // dd if=/dev/zero bs=1024 count=$((500 * 1024)) | gzip -9 > zeroes.gz // // and replace the zeroes.gz file used in the test. + decode_wasm(Arc::new(compressed_test_contents("zeros.gz"))).unwrap(); +} + +#[test] +#[should_panic(expected = "specified uncompressed size 100 does not match extracted size 101")] +fn test_decode_large_compressed_module_with_tweaked_size() { let mut contents = compressed_test_contents("zeros.gz"); let n = contents.len(); contents[n - 4..n].copy_from_slice(&100u32.to_le_bytes()); diff --git a/rs/replicated_state/src/canister_state/system_state/wasm_chunk_store.rs b/rs/replicated_state/src/canister_state/system_state/wasm_chunk_store.rs index 0ce6124a91f..0561fa2ca21 100644 --- a/rs/replicated_state/src/canister_state/system_state/wasm_chunk_store.rs +++ b/rs/replicated_state/src/canister_state/system_state/wasm_chunk_store.rs @@ -8,7 +8,7 @@ use crate::{page_map::PageAllocatorFileDescriptor, PageMap}; const PAGES_PER_CHUNK: u64 = 256; const CHUNK_SIZE: u64 = PAGES_PER_CHUNK * (PAGE_SIZE as u64); -pub(crate) const DEFAULT_MAX_SIZE: NumBytes = NumBytes::new(100 * 1024 * 1024); // 100 MiB +pub const DEFAULT_MAX_SIZE: NumBytes = NumBytes::new(100 * 1024 * 1024); // 100 MiB #[test] fn check_chunk_size() {