{"record":{"id":"5283657daa436fcb","repo":"swc-project/swc","slug":"should-able-to-convert-size","errorCode":null,"errorMessage":"Should able to convert size","messagePattern":"Should able to convert size","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_plugin_runner/src/transform_executor.rs","lineNumber":56,"sourceCode":"#[cfg(feature = \"encoding-impl\")]\nimpl PluginTransformState {\n    fn run(\n        mut self,\n        program: &PluginSerializedBytes,\n        unresolved_mark: swc_common::Mark,\n        should_enable_comments_proxy: Option<bool>,\n    ) -> Result<PluginSerializedBytes, Error> {\n        let should_enable_comments_proxy =\n            u32::from(should_enable_comments_proxy.unwrap_or_default());\n\n        // Copy host's serialized bytes into guest (plugin)'s allocated memory.\n        let guest_program_ptr = write_into_memory_view(\n            &mut *self.instance.caller()?,\n            program,\n            |caller, serialized_len| {\n                let serialized_len = serialized_len\n                    .try_into()\n                    .expect(\"Should able to convert size\");\n                caller.alloc(serialized_len).unwrap_or_else(|_| {\n                    panic!(\"Should able to allocate memory for the size of {serialized_len}\")\n                })\n            },\n        );\n\n        let returned_ptr_result = self.instance.transform(\n            guest_program_ptr.0,\n            guest_program_ptr.1,\n            unresolved_mark.as_u32(),\n            should_enable_comments_proxy,\n        )?;\n\n        self.instance\n            .caller()?\n            .free(guest_program_ptr.0, guest_program_ptr.1)?;\n        self.instance.cleanup()?;\n","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_plugin_runner/src/transform_executor.rs#L38-L74","documentation":"In PluginTransformState::run, the serialized program length (usize) is converted with try_into() into the i32 size argument for caller.alloc before copying the AST into the plugin's memory. The expect panics when the serialized AST exceeds the i32 range (~2 GiB) - the wasm trampoline cannot express such a size.","triggerScenarios":"Compiler.process_js (or any path through swc_plugin_runner's transform executor) with experimental.plugins configured and a single program whose serialized AST is over ~2 GiB.","commonSituations":"Concatenated monolithic bundles or giant generated modules run through a plugin instead of being transformed per module.","solutions":["Transform per file/module so each serialized program stays well under the limit.","Exclude enormous generated files (data modules, base64 assets) from plugin transforms.","If the input legitimately exceeds 2 GiB serialized, split it at the build-tooling level (bundler/CodeSplitting) before SWC."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Enforce per-transform input limits before invoking plugin transforms;\n// the serialized AST must stay under the i32 (~2 GiB) trampoline range.\nfn assert_single_transform_limit(src: &str) -> anyhow::Result<()> {\n    if src.len() > 256 * 1024 * 1024 {\n        anyhow::bail!(\"file too large ({ } bytes) for plugin transform; split or exclude it\", src.len());\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Transform file-by-file; never concatenate modules before a plugin pass.","Route data/asset modules around plugin transforms in your bundler config.","Add a size guard at the tool boundary so oversized files fail loudly instead of panicking."],"tags":["integer-overflow","plugin","serialization","panic"],"backgroundTag":"integer-conversion-overflow","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}