Learn/Remade with Rust

After FORCEDENTRY: a pure-Rust JBIG2 decoder for scanned PDFs

A JBIG2 bug in an iPhone PDF parser was a zero-click exploit in 2021. On 25 November 2026 Remade with Rust shipped rusty_jbig2 and rusty_jpx, two PDF image decoders in Rust.

Signed by Tim Almond·
Three black-and-white scanned pages hang from wooden clothes pegs on a cord in a garage workshop, lit by low late-afternoon sun from an open side door
Is there a pure-Rust JBIG2 decoder for PDF scan images?

Yes. rusty_jbig2 0.1.0 went to crates.io on 25 November 2026 from the remade_ffmpeg_rs workspace. It decodes JBIG2 streams as PDF embeds them, with shared globals, and matched the reference image on all 269 test streams in its pull request. A JPEG 2000 sibling, rusty_jpx, shipped the same day.

A scanned contract, a bank statement saved from a multifunction printer, a medical form someone faxed to your inbox: the pages look like plain paper, but inside the PDF they are compressed images, and something on your computer has to unpack them. On 25 November 2026 the Remade with Rust team I work with merged two new pure-Rust crates for exactly that job into remade_ffmpeg_rs. The first is a JBIG2 decoder, rusty_jbig2. The second, rusty_jpx, reads JPEG 2000. Both reached crates.io the same afternoon.

The work was tracked in issue 132, opened on 19 November. It named three image filters PDFs use that no house crate covered: JBIG2Decode, JPXDecode and CCITTFaxDecode. This post explains why the first of those has a history worth knowing, what shipped, and what the release does not yet claim.

Why a JBIG2 decoder carries security history

JBIG2 is a compression standard, ITU-T T.88, built for pages that are only black and white. It cuts a page into shapes, stores each repeated shape once in a dictionary, and redraws the page from references to it. That makes scans tiny. It also means the decoder runs a small drawing program written by whoever made the file.

In December 2021, Google Project Zero published its teardown of FORCEDENTRY, the zero-click iMessage exploit attributed to NSO. The attack sent a PDF disguised as a GIF. Apple's CoreGraphics parser opened it, and the JBIG2 code inside, which came from Xpdf, had an integer overflow. Apple's iOS 14.8 security notes list it as CVE-2021-30860, credit The Citizen Lab, and say it may have been actively exploited. The NVD entry records the same flaw.

The lesson is not that JBIG2 is evil. A format your phone decodes without asking is attack surface, and C parsers for old formats are where memory bugs have lived for decades. CISA's case for memory-safe roadmaps makes that argument for the whole industry. MATA's answer is the one in why Remade with Rust matters: rebuild the primitives in a memory-safe language and keep the files on hardware you own.

What shipped in remade_ffmpeg_rs on 25 November

Two pull requests landed the decoders, and two more tuned them the same day. Version 0.1.0 of each crate went to crates.io early in the afternoon, Phoenix time. The tuned code is on main, and release pull request 217 bumps each crate to 0.1.1, so check which version crates.io serves before you rely on the faster build.

rusty_jbig2: written from the standard, checked against reference images

Pull request 220 adds the crate. It was written from T.88 itself, with no code taken from jbig2dec or Ghostscript, which were only run as black boxes. It handles generic, refinement, text and halftone regions, arithmetic, Huffman and MMR coding, and PDF's habit of putting shared symbols in a separate globals stream.

The evidence is a table of 269 test streams from the SerenityOS and hayro JBIG2 suites, compared against each suite's own reference images. All 269 matched exactly. 267 are committed as tests, and the two largest files were run by hand. Where the hayro-jbig2 0.4.0 crate disagreed with a reference image, the new decoder agreed with the reference. A JBIG2 decoder that only matches another decoder can inherit its mistakes, so scoring against the suites' own images is the stronger test.

rusty_jpx: JPEG 2000 inside PDFs and on its own

Pull request 222 adds rusty_jpx, written from ISO/IEC 15444-1, the JPEG 2000 core standard that ITU also publishes as T.800. It reads raw codestreams and JP2 or JPX files, including the soft mask a PDF can store inside the image.

Its pull request compares full sample buffers against OpenJPEG 2.5.4. All 23 class 1 reference streams from the conformance standard fell within their error limits, and every lossless stream came out exact. Where results differ, the request lists each case and its suspected cause instead of hiding it.

The CCITT fax filter, added to rusty_tiff

The third PDF filter did not need a new crate. rusty_tiff already decoded CCITT Group 3 and Group 4 fax data for TIFF. PR 220 added a separate decode_filter path that takes PDF's own parameters, including damaged-row handling, and left the existing TIFF path untouched.

What these decoders do and do not promise

A release note is only useful if it is honest about the edges. These crates are new, and their pull requests say where the testing stops.

Bounded work on hostile files

Both crates return errors instead of panicking on bad input, and both take limits on pixels, samples, symbols or work, so a tiny file cannot demand gigabytes. The JBIG2 tests cover truncation, byte flips and symbol bombs. The JPEG 2000 tests ran 110,000 random mutations, plus 86,000 with overflow checks on, with no panic. The JBIG2 fuzzing run was short, and its author calls it "a smoke test, not a campaign." For rusty_jpx, the fuzz target exists but cargo-fuzz itself was not run.

One small unsafe module each

The speed work in pull requests 225 and 226 cut the instructions each decoder executes by about a third to a half, without changing a byte of output. To get there, each crate now keeps one private module of unsafe code, and the READMEs were corrected to stop claiming none. The public API is safe, and the rest of each crate denies unsafe code. Neither crate has had an independent security audit.

Decode only, not yet in the pipeline

There is no encoder in either crate. JBIG2 colour extensions are refused, and JPEG 2000 colour spaces are reported, not converted. Neither crate is wired into the rff command line, and the planned render of a real scanned-PDF corpus against other decoders has not been published yet. If you build a document tool in Rust, you can add both from crates.io today. If you just open scans, nothing on your machine changes until an app adopts them. The wider media rebuild is described in the remade_ffmpeg_rs pipeline overview, the Remade with Rust hub collects the crates, and the Learn library has the rest. MATA's case for keeping your documents local starts with the Digital Freedom guide.

FAQ

Short answers already in this article.

What did FORCEDENTRY have to do with JBIG2?

Google Project Zero's December 2021 analysis shows the exploit hid a PDF inside a fake GIF and attacked the JBIG2 code in Apple's CoreGraphics PDF decoder, code that came from Xpdf. Apple fixed it in iOS 14.8 as CVE-2021-30860, an integer overflow that may have been actively exploited.

Which PDF image filters do the new crates cover?

rusty_jbig2 covers JBIG2Decode, the black-and-white scan format. rusty_jpx covers JPXDecode, which is JPEG 2000 inside a PDF, plus standalone J2K and JP2 files. The third scan filter, CCITTFaxDecode, gained PDF parameter support in rusty_tiff through a new decode_filter function.

Does memory-safe Rust mean these decoders cannot have security bugs?

No. Rust removes whole classes of memory bugs, but logic errors, slow inputs and huge allocations are still possible. Each crate bounds its work with explicit limits, and each now keeps one small unsafe block in a private kernels module for speed. Neither crate has had an independent audit.

What is missing from the first release of each crate?

Both crates decode only. JBIG2 colour extensions return Unsupported. rusty_jpx refuses HTJ2K and JPEG 2000 Part 2 extensions and does not convert colour spaces. Neither crate is wired into the rff command line yet, and no run over a real scanned-PDF corpus has been published.

How do I add the decoders to a Rust project?

Add rusty_jbig2 = "0.1" and rusty_jpx = "0.1" to Cargo.toml. Call decode_jbig2 with the page stream and optional globals, or decode_jpx with the image bytes. Both are Apache-2.0, have no dependencies and build on Rust 1.85 or newer.