{"record":{"id":"ee4d492ae3e7dd76","repo":"run-llama/liteparse","slug":"failed-to-construct-rgb-image-from-width-x-height","errorCode":null,"errorMessage":"failed to construct RGB image from {width}x{height} buffer","messagePattern":"failed to construct RGB image from (.+?)x(.+?) buffer","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"crates/liteparse/src/ocr/oar.rs","lineNumber":287,"sourceCode":"        .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,\n            format!(\"failed to construct RGB image from {width}x{height} buffer\"),\n        )\n    })\n}\n\nfn region_to_result(region: oar_ocr::oarocr::TextRegion) -> Option<OcrResult> {\n    let text = region.text?.trim().to_owned();\n    let confidence = region.confidence?;\n    if text.is_empty() || !confidence.is_finite() {\n        return None;\n    }\n\n    let points = &region.bounding_box.points;\n    if points.is_empty()\n        || points\n            .iter()\n            .any(|point| !point.x.is_finite() || !point.y.is_finite())","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/run-llama/liteparse/blob/22d2dd8cd7f7b9320102b57ddaf0e663ff7d15a8/crates/liteparse/src/ocr/oar.rs#L269-L305","documentation":"As the final step, rgb_image calls image::RgbImage::from_raw(width, height, vec). Despite the earlier explicit length check, from_raw can still fail (it re-validates that the buffer size matches the dimensions and may hit allocator limits); if it returns None this error is produced. In practice this is a defensive backstop indicating the image crate refused to build the image.","triggerScenarios":"Calling the OCR recognize path where dimensions and buffer length pass the earlier checks but image::RgbImage::from_raw still returns None (e.g. allocator failure for the huge to_vec() copy, or an image-crate version whose internal validation rejects the input).","commonSituations":"Memory exhaustion while copying a very large buffer; mismatches between the liteparse expectation and the installed `image` crate's validation behavior after a dependency upgrade.","solutions":["Free memory or reduce the image size; the to_vec() copy can fail under memory pressure.","Verify the `image` crate version is the one LiteParse was built against and update if the ecosystem changed.","If it persists, log width/height/buffer length and file an issue with a reproducer."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match ocr.recognize_sync(&buf, w, h) {\n    Ok(res) => use(res),\n    Err(e) if e.to_string().contains(\"failed to construct RGB image\") => {\n        // fall back: retry with smaller image or report OOM\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Ensure adequate memory for large image buffers (from_raw copies the data)","Pin compatible versions of the `image` crate in your lockfile","Log dimensions/lengths when this backstop fires to identify the real cause"],"tags":["ocr","image-construction","rust"],"backgroundTag":"internal-invariant-violation","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"}