{"record":{"id":"e4c18fb4793b12ca","repo":"tonhowtf/omniget","slug":"pdfium-sem","errorCode":null,"errorMessage":"PDFium sem {}: {}","messagePattern":"PDFium sem (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf.rs","lineNumber":110,"sourceCode":"    obj_bounds:\n        Option<unsafe extern \"C\" fn(Object, *mut f32, *mut f32, *mut f32, *mut f32) -> c_int>,\n    img_bitmap: Option<unsafe extern \"C\" fn(Object) -> Bitmap>,\n    bmp_format: Option<unsafe extern \"C\" fn(Bitmap) -> c_int>,\n    bmp_w: Option<unsafe extern \"C\" fn(Bitmap) -> c_int>,\n    bmp_h: Option<unsafe extern \"C\" fn(Bitmap) -> c_int>,\n}\n\nunsafe impl Send for Api {}\nunsafe impl Sync for Api {}\n\nstatic API: Mutex<Option<&'static Api>> = Mutex::new(None);\n/// O PDFium não é thread-safe: toda operação segura este lock.\nstatic OPS: Mutex<()> = Mutex::new(());\n\nunsafe fn sym<T: Copy>(lib: &libloading::Library, name: &[u8]) -> anyhow::Result<T> {\n    Ok(*lib\n        .get::<T>(name)\n        .map_err(|e| anyhow!(\"PDFium sem {}: {}\", String::from_utf8_lossy(name), e))?)\n}\n\n/// Igual ao `sym`, mas o símbolo pode faltar: devolve `None` em vez de erro.\nunsafe fn opt_sym<T: Copy>(lib: &libloading::Library, name: &[u8]) -> Option<T> {\n    lib.get::<T>(name).ok().map(|s| *s)\n}\n\nfn api() -> anyhow::Result<&'static Api> {\n    let mut guard = API.lock().unwrap_or_else(|p| p.into_inner());\n    if let Some(a) = *guard {\n        return Ok(a);\n    }\n    let path = crate::core::pdfium::resolve_path()\n        .ok_or_else(|| anyhow!(\"PDFium nao esta instalado (Ajustes → Dependencias → PDFium)\"))?;\n    let lib = unsafe { libloading::Library::new(&path) }\n        .map_err(|e| anyhow!(\"nao carregou o PDFium em {}: {}\", path.display(), e))?;\n    let api = unsafe {\n        let init: unsafe extern \"C\" fn() = sym(&lib, b\"FPDF_InitLibrary\\0\")?;","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf.rs#L92-L128","documentation":"pdf.rs's unsafe sym<T> helper wraps libloading Library::get failures: a required PDFium C symbol could not be resolved from the loaded library. This means the loaded shared library is not the expected PDFium (or is an incompatible build missing that export). The message names the missing symbol (e.g. FPDF_InitLibrary) plus the libloading error.","triggerScenarios":"Loading a PDFium shared library whose build lacks a required export — a stub/wrong library placed at the resolved path, a severely outdated or incompatible PDFium build, or symbol name mismatch on an unusual platform build.","commonSituations":"User configured 'pdfium.dll' that is actually a different PDF library; distro PDFium builds with different symbol visibility; mixed-version PDFium where newer API symbols (LoadMemDocument64, etc.) do not exist in an old library.","solutions":["Replace the PDFium library with a complete official build (pdfium-binaries / bundled dependency) matching the platform","Check that the resolved path really points to PDFium (not a similarly named library)","Use a PDFium build recent enough to export all required FPDF_* symbols (e.g. FPDF_LoadMemDocument64)","If the symbol is genuinely optional, use the crate's opt_sym path instead of the required one"],"exampleFix":"// before\nlet lib = unsafe { libloading::Library::new(path) }?;\nlet f = unsafe { sym::<LoadMemDoc>(&lib, b\"FPDF_LoadMemDocument64\\0\")? }; // 'PDFium sem ...'\n// after\nlet f = match unsafe { opt_sym::<LoadMemDoc>(&lib, b\"FPDF_LoadMemDocument64\\0\") } {\n    Some(f) => f,\n    None => return Err(anyhow!(\"PDFium desatualizado: reinstale em Ajustes → Dependências\")),\n};","handlingStrategy":"try-catch","validationCode":"// probe the library before use\nlet lib = unsafe { libloading::Library::new(pdfium_path) }\n    .map_err(|e| anyhow!(\"PDFium inválido em {}: {e}\", pdfium_path.display()))?;\nunsafe { lib.get::<usize>(b\"FPDF_InitLibrary\\0\") }\n    .map_err(|_| anyhow!(\"PDFium incompleto: reinstale em Ajustes → Dependências\"))?;","typeGuard":null,"tryCatchPattern":"match pdf::info(&path) {\n    Err(e) if e.to_string().contains(\"PDFium sem \") => {\n        eprintln!(\"{e}\\nBiblioteca PDFium incompatível — reinstale via Ajustes → Dependências.\");\n    }\n    other => other?,\n}","preventionTips":["Ship a known-good bundled PDFium build per platform","Verify all required FPDF_* symbols at load time (fail once with a clear message)","Do not let users point at arbitrary system libraries; prefer the managed dependency installer","Pin/document the minimum PDFium version required"],"tags":["rust","pdfium","libloading","missing-symbol","native-library"],"backgroundTag":"missing-dependency","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}