kkpdf-zed adheres to strict zero-trust defensive engineering standards.
- Architecture:
kkpdf-zeddynamically binds to Google's C++ Pdfium rendering engine. - Risk: Malformed or weaponized PDF exploit payloads targeting memory vulnerabilities (heap buffer overflows, use-after-free) in PDF parsing libraries.
- Mitigation & Invariants:
- All FFI calls to Pdfium are wrapped in
SerializedPdfiumunder aparking_lot::Mutex, guaranteeing strict serial access across threads. - Pre-flight magic-byte validation (
%PDF-header check) rejects non-PDF payloads prior to invoking parser state machines. - In a full Zed integration, Pdfium rendering runs on background executor tasks, preventing UI thread blockage and isolating crash surfaces.
- All FFI calls to Pdfium are wrapped in
- Risk: Decompression bombs or massive 10,000-page PDF documents consuming gigabytes of RAM leading to Out-Of-Memory (OOM) editor crashes.
- Mitigation & Invariants:
- Viewport-bounded rendering: Only pages visible on screen or in prefetch radius are rasterized.
- Memory-budgeted LRU cache (
PageLruCache): Bounded byDEFAULT_MEMORY_BUDGET_BYTES(256 MB default). Automatic byte-size eviction purges oldest bitmaps when total allocation exceeds the budget. - Bitmaps larger than the total cache budget are bypassed rather than overflowing system memory.
- Risk: Malicious symlink loops or continuous file rewrite flood attacks exhausting CPU cycles.
- Mitigation & Invariants:
- Debounced file watching (
PdfReloadDebouncer): Coalesces rapid filesystem events (e.g. fromlatexmkortypst watch) with configurable debounce windows (200ms default). - Atomic reload lock: State snapshots are captured before re-reading bytes, ensuring corrupted partial writes fail closed without corrupting the active viewer state.
- Debounced file watching (
- Undocumented Unsafe Prohibition:
#![deny(clippy::undocumented_unsafe_blocks)]is strictly enforced. Everyunsafeblock must include explicit// SAFETY:rationale documenting invariant safety proofs. - Zero Debug / Todo Leftovers:
#![deny(clippy::dbg_macro)]and#![deny(clippy::todo)]are enforced across all build targets. - No Unchecked Unwraps: Production rendering routines use
anyhow::Resultcontext chaining and fallback gracefully if library bindings are unavailable.
If you discover a potential security vulnerability in kkpdf-zed:
- Email: Kushagra Kumar (kkushagra86@gmail.com)
- Response SLA: Initial triage within 24 hours.
- Please do not open public issues detailing reproducible exploit payloads until a patch is released.