{"record":{"id":"a1e4e3119caea83c","repo":"run-llama/liteparse","slug":"rgb-image-dimensions-overflow-width-x-height","errorCode":null,"errorMessage":"RGB image dimensions overflow: {width}x{height}","messagePattern":"RGB image dimensions overflow: (.+?)x(.+?)","errorType":"validation","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"crates/liteparse/src/ocr/oar.rs","lineNumber":270,"sourceCode":"        eprintln!(\n            \"[oar-ocr] ignoring OcrOptions::language ({language:?}); recognition language is fixed by the model and character dictionary\"\n        );\n    });\n}\n\nfn rgb_image(image_data: &[u8], width: u32, height: u32) -> Result<image::RgbImage, io::Error> {\n    if width == 0 || height == 0 {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidInput,\n            format!(\"invalid zero-sized RGB image: {width}x{height}\"),\n        ));\n    }\n\n    let expected_len = (width as usize)\n        .checked_mul(height as usize)\n        .and_then(|pixels| pixels.checked_mul(3))\n        .ok_or_else(|| {\n            io::Error::new(\n                io::ErrorKind::InvalidInput,\n                format!(\"RGB image dimensions overflow: {width}x{height}\"),\n            )\n        })?;\n\n    if image_data.len() != expected_len {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidInput,\n            format!(\n                \"invalid RGB buffer length for {width}x{height}: expected {expected_len} bytes, got {}\",\n                image_data.len()\n            ),\n        ));\n    }\n\n    image::RgbImage::from_raw(width, height, image_data.to_vec()).ok_or_else(|| {\n        io::Error::new(\n            io::ErrorKind::InvalidInput,","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/run-llama/liteparse/blob/22d2dd8cd7f7b9320102b57ddaf0e663ff7d15a8/crates/liteparse/src/ocr/oar.rs#L252-L288","documentation":"rgb_image computes the expected buffer size as width * height * 3 using checked arithmetic. If either multiplication would overflow usize, the declared dimensions cannot correspond to any real buffer, so the call is rejected with this InvalidInput error. This prevents overflow-based miscalculation of buffer lengths downstream.","triggerScenarios":"Calling the OCR recognize path with width/height values so large that width*height*3 exceeds the platform's usize maximum (practically, absurd dimensions like > ~1.7e15 pixels on 64-bit).","commonSituations":"Corrupt image metadata or a malicious/buggy OCR server reporting fantastical dimensions; integer-typed width/height read from an untrusted header without bounds checking.","solutions":["Validate/sane-check width and height (e.g. cap at a few tens of millions of pixels) before calling the OCR API.","Fix the upstream source that reports the oversized dimensions.","If huge images are legitimate, process them in tiles rather than passing full dimensions."],"exampleFix":"// before: unchecked dimensions from external source\nlet (w, h) = header.dimensions();\nocr.recognize_sync(&buf, w, h)?;\n\n// after: bounds check first\nconst MAX_DIM: u32 = 100_000_000;\nif w > MAX_DIM || h > MAX_DIM {\n    return Err(anyhow!(\"unreasonable image dimensions: {w}x{h}\"));\n}\nocr.recognize_sync(&buf, w, h)?;","handlingStrategy":"validation","validationCode":"// Rust: sane upper bound on image dimensions\nconst MAX_DIM: u32 = 100_000_000;\nfn dims_in_range(w: u32, h: u32) -> bool {\n    w > 0 && w <= MAX_DIM && h > 0 && h <= MAX_DIM\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bounds-check externally sourced width/height before use","Never trust image metadata from untrusted producers","Tile very large images instead of passing full dimensions"],"tags":["ocr","integer-overflow","image-validation","rust"],"backgroundTag":"value-out-of-range","analyzedSha":"22d2dd8cd7f7b9320102b57ddaf0e663ff7d15a8","analyzedAt":"2026-09-08T06:09:49.009Z","contentChangedAt":"2026-09-08T06:09:49.009Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}