How a One-Line Bug in Browser PDF Compression Shipped Empty File Downloads
A developer building a fully client-side PDF compressor discovered a subtle bug where pdf.js transferred the file's ArrayBuffer to its worker thread, silently detaching the original buffer and leaving it empty. This caused a fallback branch — designed to return the original file when compression offered no benefit — to instead deliver a zero-byte download to users. The issue went undetected in production because it only triggered for already-optimized PDFs, a case that had not been tested. The fix required copying the buffer before passing it to pdf.js, ensuring the original bytes remained accessible. The article also outlines broader challenges of browser-based PDF compression, including the trade-off between lossless structure rebuilding and lossy page re-rendering, memory risks on mobile, and the importance of never returning a larger file than the original.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in