{"record":{"id":"f076758cf9d1a9bf","repo":"neon-bindings/neon","slug":"size-i32-max","errorCode":null,"errorMessage":"{size} >= i32::MAX","messagePattern":"(.+?) >= i32::MAX","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/neon/src/types_impl/utf8.rs","lineNumber":50,"sourceCode":"impl<'a> Utf8<'a> {\n    pub fn size(&self) -> usize {\n        self.contents.len()\n    }\n\n    pub fn into_small(self) -> Option<SmallUtf8<'a>> {\n        if self.size() < SMALL_MAX {\n            Some(SmallUtf8 {\n                contents: self.contents,\n            })\n        } else {\n            None\n        }\n    }\n\n    pub fn into_small_unwrap(self) -> SmallUtf8<'a> {\n        let size = self.size();\n        self.into_small().unwrap_or_else(|| {\n            panic!(\"{size} >= i32::MAX\");\n        })\n    }\n\n    pub fn truncate(self) -> SmallUtf8<'a> {\n        let size = self.size();\n        let mut contents = self.contents;\n\n        if size >= SMALL_MAX {\n            let s: &mut String = contents.to_mut();\n            s.truncate(SMALL_MAX - 3);\n            s.push_str(\"...\");\n        }\n\n        SmallUtf8 { contents }\n    }\n}\n","sourceCodeStart":32,"sourceCodeEnd":67,"githubUrl":"https://github.com/neon-bindings/neon/blob/38960e4381d9ad13b551cdf2d261f609167c9bc2/crates/neon/src/types_impl/utf8.rs#L32-L67","documentation":"`Utf8::into_small_unwrap` converts a UTF-8 buffer to a `SmallUtf8`, which is only valid when the byte length fits in an `i32` (a Node-API limitation for small strings). If `size() >= i32::MAX` (2 GiB), the conversion returns None and this method panics with the size. It is the panicking sibling of the fallible `into_small`.","triggerScenarios":"Calling `into_small_unwrap()` on a `Utf8` value whose string is 2,147,483,647 bytes or larger — e.g. reading a gigantic file into a JS string and then converting it; concatenating very large strings before conversion.","commonSituations":"Processing multi-gigabyte text files, logs, or serialized payloads through JS strings; string-building code that accumulates past the 2 GiB boundary before calling into_small_unwrap.","solutions":["Use the fallible `into_small()` and handle the None case instead of the `_unwrap` variant.","Check `self.size() < i32::MAX as usize` before calling into_small_unwrap.","Process the data in chunks (streaming read/truncate) rather than holding one >2 GiB string; `truncate()` is provided for this.","Reduce memory pressure: if strings near 2 GiB are expected, switch the pipeline to operate on Buffers/bytes rather than JS strings."],"exampleFix":"// before\nlet small = utf8.into_small_unwrap(); // panics for >= 2 GiB strings\n\n// after\nlet small = match utf8.into_small() {\n    Some(s) => s,\n    None => return cx.throw_error(\"string exceeds 2 GiB limit\"),\n};","handlingStrategy":"validation","validationCode":"// before converting, check the size bound\nif utf8.size() >= i32::MAX as usize {\n    return cx.throw_error(\"string too large for SmallUtf8 (>= 2 GiB)\");\n}\nlet small = utf8.into_small_unwrap(); // now safe","typeGuard":"fn fits_small_utf8(u: &Utf8) -> bool {\n    u.size() < i32::MAX as usize\n}","tryCatchPattern":"// prefer the fallible API and handle the None case explicitly\nlet small = utf8.into_small();\nif small.is_none() { /* chunk or truncate the string instead */ }","preventionTips":["Prefer into_small() over into_small_unwrap() for untrusted sizes","Stream or chunk very large text instead of materializing multi-GB JS strings","Cap input sizes at the application layer before they reach string conversion","Use truncate() when only a prefix of a huge string is needed"],"tags":["rust","neon","strings","limits"],"backgroundTag":"value-out-of-range","analyzedSha":"38960e4381d9ad13b551cdf2d261f609167c9bc2","analyzedAt":"2026-09-13T09:05:33.640Z","contentChangedAt":"2026-09-13T09:05:33.640Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}