//! Fuzz the standard security handler. //! //! The /Encrypt dictionary and every value key derivation consumes are //! attacker-controlled: /O, /U, /P, /Length, the crypt filter names and the //! file id all come straight from the file. A malformed one must produce a //! typed error, never a panic or an unbounded loop. #![no_main] use libfuzzer_sys::fuzz_target; use nigig_pdf_cos::encrypt::Decryptor; use nigig_pdf_cos::{Lexer, PdfObj}; use nigig_pdf_document::PdfDocument; fuzz_target!(|data: &[u8]| { // Interpret the input as an /Encrypt dictionary where it parses as one. let mut lexer = Lexer::new(data, 0); if let Ok(PdfObj::Dict(dict)) = lexer.read_object() { // Both an empty and a non-empty password: the two authentication // paths differ, and the owner-password path re-derives the key. let _ = Decryptor::new(&dict, data, b""); let _ = Decryptor::new(&dict, data, data); } // And as a whole document, which reaches key derivation through the // real trailer path. if let Ok(mut doc) = PdfDocument::parse(data) { for index in 0..doc.page_count().min(2) { let _ = doc.page(index); } } let _ = PdfDocument::parse_with_password(data, b"password"); });