{"record":{"id":"0515bf601a05e002","repo":"tonhowtf/omniget","slug":"nenhum-objeto-encontrado-arquivo-vazio-ou-cifrado","errorCode":null,"errorMessage":"nenhum objeto encontrado — arquivo vazio ou cifrado","messagePattern":"nenhum objeto encontrado — arquivo vazio ou cifrado","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf_repair.rs","lineNumber":351,"sourceCode":"        } else {\n            decoded.len()\n        };\n        if start <= stop && stop <= decoded.len() {\n            out.push((num, decoded[start..stop].to_vec()));\n        }\n    }\n    out\n}\n\n/// Reescreve o arquivo com uma xref nova no fim. Devolve `(bytes, objetos)`.\npub fn rebuild_xref(data: &[u8]) -> anyhow::Result<(Vec<u8>, usize)> {\n    let head = find_first(data, b\"%PDF-\")\n        .ok_or_else(|| anyhow!(\"não achei a assinatura %PDF- — o arquivo não parece um PDF\"))?;\n    // Lixo antes do cabeçalho desloca todos os offsets: corta fora.\n    let body = &data[head..];\n    let objects = scan_objects(body);\n    if objects.is_empty() {\n        return Err(anyhow!(\n            \"nenhum objeto encontrado — arquivo vazio ou cifrado\"\n        ));\n    }\n\n    let mut out = body.to_vec();\n    if !out.ends_with(b\"\\n\") {\n        out.push(b'\\n');\n    }\n    let mut by_num: std::collections::BTreeMap<u32, (usize, u16)> =\n        objects.iter().map(|(n, o, g)| (*n, (*o, *g))).collect();\n\n    // PDF 1.5+ comprime objeto dentro de objeto. Reescreve cada um solto no\n    // fim do arquivo — é o que deixa a xref plana voltar a fazer sentido.\n    let mut unpacked = 0usize;\n    for idx in 0..objects.len() {\n        let (a, b) = object_body(body, &objects, idx);\n        for (num, content) in expand_object_stream(&body[a..b]) {\n            if by_num.contains_key(&num) {","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf_repair.rs#L333-L369","documentation":"After locating the `%PDF-` header and cutting leading junk, `rebuild_xref` scans for objects with `scan_objects(body)`. If no `N G obj ... endobj` pairs are found, the file has a PDF header but no parseable objects, so a cross-reference table cannot be rebuilt. The message hints the file is empty or encrypted.","triggerScenarios":"Input where the body is entirely encrypted (no plaintext objects), a header-only stub/truncated file, or a file whose object syntax is too mangled for `scan_objects` to recognize any `obj`/`endobj` pair.","commonSituations":"PDFs with heavy encryption whose streams and dictionaries are not plaintext; downloads truncated to just the first bytes; files where a previous 'repair' tool stripped the body; binary content mangled by text-mode transfer (CRLF/null-byte corruption).","solutions":["Try opening the file in a normal viewer — if it asks for a password, it is encrypted and this repair path is not applicable; decrypt first","Check that the file is not truncated (compare against expected size / try re-downloading)","Inspect the body with a hex dump for ` obj` markers; if present but unparsed, the object syntax is nonstandard","If the transfer corrupted the bytes (ASCII-mode FTP, text email), retransfer in binary mode"],"exampleFix":"// before\nlet (bytes, objs) = rebuild_xref(&data)?;\n// after\nmatch rebuild_xref(&data) {\n    Ok((bytes, objs)) => { /* repair succeeded */ }\n    Err(e) if e.to_string().contains(\"nenhum objeto\") => {\n        eprintln!(\"file is empty or encrypted; trying password decryption first\");\n    }\n    Err(e) => return Err(e),\n}","handlingStrategy":"validation","validationCode":"fn has_plaintext_objects(data: &[u8]) -> bool {\n    data.windows(5).filter(|w| w == b\"%PDF-\")\n        .next()\n        .map(|_| data.windows(4).any(|w| w == b\" obj \"))\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match rebuild_xref(&data) {\n    Err(e) if e.to_string().contains(\"nenhum objeto\") => {\n        eprintln!(\"empty or encrypted PDF — prompt for a password or re-export\");\n    }\n    other => other?,\n}","preventionTips":["Detect encryption markers (/Encrypt in trailer) up front and handle passwords separately","Check file completeness against the source size before repair","Avoid text-mode transfers (FTP/email) that corrupt binary PDF bodies","Warn users that files already processed by other 'repair' tools may have stripped bodies"],"tags":["pdf","parsing","corrupt-file","rust"],"backgroundTag":"empty-result-set","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"}