Corrupted & Malformed PDF Files
The internet is a hostile environment. Users routinely upload PDFs that were interrupted during download, maliciously modified, or simply saved with the wrong extension. Your application must handle these gracefully without crashing the server or hanging in an infinite loop.
This suite of intentionally malformed files tests the absolute limits of your parser's resilience. From completely empty 0-byte files to severed Cross-Reference (xref) streams and invalid object references, these files guarantee you can catch exceptions cleanly.
0-Byte Empty File
An entirely empty file containing exactly 0 bytes. Excellent for testing if your parser throws an immediate, clean error or crashes with a NullPointer exception.
Whitespace only streams
A PDF where the content stream is populated entirely with null bytes and spaces. Tests buffering efficiency on empty data.
Invalid object references
A PDF where the page tree points to a non-existent child object, ensuring parsers handle dangling pointers gracefully.
Duplicate object IDs
A PDF declaring the same structural Object ID twice, testing dictionary collision resolution.
Truncated
A valid PDF that was sliced exactly in half. Simulates a severe network interruption during upload.
Missing EOF Marker
A PDF where the absolute final `%%EOF` marker has been deleted. Tests backward-scanning parser limits.
Wrong MIME type
A valid PDF file renamed with a `.txt` extension. Tests if your system relies on file extensions or reads the actual magic bytes.
Corrupted
A PDF where a block of internal bytes has been randomized. The trailer is intact, but the internal objects are destroyed.
Renamed extension
A valid PDF file renamed to `.jpg`. Tests if your image processors correctly reject non-image payloads.
Stream length mismatch
A PDF where the `/Length` dictionary value does not match the actual byte length of the stream, testing dynamic stream-boundary detection.
Broken Cross-Reference Table
A PDF where the Cross-Reference table byte offsets are intentionally shifted. Tests xref reconstruction algorithms.
Frequently Asked Questions
Use Cases
- Testing parser resilience to ensure malformed files trigger handled exceptions rather than fatal segmentation faults.
- Validating magic-byte (MIME type) detection logic to ensure a `.jpg` renamed to `.pdf` is correctly rejected.
- Ensuring network interruption handling correctly identifies truncated binary payloads.