{"record":{"id":"193a402dc053cf74","repo":"swc-project/swc","slug":"invalid-utf8-193a40","errorCode":null,"errorMessage":"invalid utf8","messagePattern":"invalid utf8","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_sourcemap/src/lazy/mod.rs","lineNumber":648,"sourceCode":"                encode_rmi(&mut buf, &rmi_data);\n                rmi_data.clear();\n            }\n\n            buf.push(b';');\n            prev_line += 1;\n            had_rmi = false;\n            idx_of_first_in_line = idx;\n        }\n    }\n    if empty {\n        return None;\n    }\n\n    if had_rmi {\n        encode_rmi(&mut buf, &rmi_data);\n    }\n\n    Some(String::from_utf8(buf).expect(\"invalid utf8\"))\n}\n\nfn serialize_mappings(sm: &SourceMap) -> String {\n    let mut rv = String::new();\n    // dst == minified == generated\n    let mut prev_dst_line = 0;\n    let mut prev_dst_col = 0;\n    let mut prev_src_line = 0;\n    let mut prev_src_col = 0;\n    let mut prev_name_id = 0;\n    let mut prev_src_id = 0;\n\n    for (idx, token) in sm.tokens.iter().enumerate() {\n        if token.dst_line != prev_dst_line {\n            prev_dst_col = 0;\n            while token.dst_line != prev_dst_line {\n                rv.push(';');\n                prev_dst_line += 1;","sourceCodeStart":630,"sourceCodeEnd":666,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_sourcemap/src/lazy/mod.rs#L630-L666","documentation":"The lazy SourceMap path duplicates serialize_range_mappings: it assembles the rangeMappings field as base64 characters plus ';' separators into a Vec<u8>, then asserts String::from_utf8 succeeds. All emitted bytes are ASCII by construction, so this expect firing means an internal swc_sourcemap bug or corrupted token state during re-serialization of a lazily decoded map, not bad user input.","triggerScenarios":"Re-encoding (to_writer/to_data) a lazily decoded SourceMap that still carries range mapping tokens, e.g. flattening or rewriting a map produced by a tool that emits rangeMappings.","commonSituations":"Sourcemap processing pipelines that decode a range-mappings map and re-emit it (chained transforms, bundler concat of maps); swc_sourcemap regressions.","solutions":["Pin swc_core/swc to the last known-good version in your pipeline.","Drop range-mapping info before re-encoding (rebuild tokens without is_range) if the field is not required downstream.","Report upstream with a minimal reproducing map."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Contain the internal assertion during re-encode of lazily decoded maps.\nlet out = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| sm.to_writer(&mut w)));\nif out.is_err() {\n    drop_range_tokens(&mut sm);\n    sm.to_writer(&mut w)?;\n}","preventionTips":["Pin the swc_core version whose sourcemap output your pipeline verifies in tests.","Drop range-mapping info before re-encoding if downstream tools do not require it.","Add encode-decode-encode round-trip tests for maps with rangeMappings."],"tags":["sourcemap","utf8","encoding","panic"],"backgroundTag":"utf8-encoding-failed","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"}