{"record":{"id":"a75f3588140491b5","repo":"run-llama/liteparse","slug":"invalid-zero-sized-rgb-image-width-x-height","errorCode":null,"errorMessage":"invalid zero-sized RGB image: {width}x{height}","messagePattern":"invalid zero-sized RGB image: (.+?)x(.+?)","errorType":"validation","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"crates/liteparse/src/ocr/oar.rs","lineNumber":260,"sourceCode":"}\n\nstatic LANGUAGE_IGNORED_WARNING: Once = Once::new();\n\n/// Warn once per process that this backend ignores `OcrOptions::language`.\nfn warn_language_ignored_once(language: &str) {\n    if language.is_empty() {\n        return;\n    }\n    LANGUAGE_IGNORED_WARNING.call_once(|| {\n        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,","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/run-llama/liteparse/blob/22d2dd8cd7f7b9320102b57ddaf0e663ff7d15a8/crates/liteparse/src/ocr/oar.rs#L242-L278","documentation":"rgb_image in the oar OCR module builds an image::RgbImage from a raw RGB byte buffer plus declared width/height. Before doing so it validates the dimensions: if either width or height is 0 the image is meaningless, so it rejects the call with this InvalidInput error. This guards against empty OCR buffers reaching the image constructor.","triggerScenarios":"Calling the OCR recognize path (recognize_sync) with an image buffer whose reported width or height is 0; also exercised by the rejects_non_rgb_buffers test path. Any caller that passes dimensions from a decoded image whose header claims zero extent triggers it.","commonSituations":"Corrupt or truncated image files whose decoded dimensions come back as 0; OCR server responses that report zero-size image metadata; passing an uninitialized/placeholder buffer to the OCR API.","solutions":["Check the source image's dimensions before OCR and skip/error early if width or height is 0.","Re-encode or re-decode the image to recover real dimensions; if the file is corrupt, replace it.","Fix the upstream producer (e.g. OCR HTTP server or renderer) that reports zero-sized images."],"exampleFix":"// before: blind OCR call with unverified dimensions\nocr.recognize_sync(&buf, width, height)?;\n\n// after: validate first\nif width == 0 || height == 0 {\n    return Err(anyhow!(\"skipping OCR: image has zero extent\"));\n}\nocr.recognize_sync(&buf, width, height)?;","handlingStrategy":"validation","validationCode":"// Rust: reject zero-dimension images before OCR\nfn dims_ok(width: u32, height: u32) -> bool {\n    width > 0 && height > 0\n}","typeGuard":"fn non_zero_dims(w: u32, h: u32) -> Option<(u32, u32)> {\n    (w > 0 && h > 0).then_some((w, h))\n}","tryCatchPattern":null,"preventionTips":["Validate decoded image dimensions before invoking OCR","Skip OCR for zero-extent images rather than passing them through","Check upstream renderers/OCR servers for zero-size metadata bugs"],"tags":["ocr","image-validation","rust"],"backgroundTag":"invalid-argument-value","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"}