Battlefront Eternal is a project of mine, a fan-made engine written in Rust that plays the 2004 game Star Wars: Battlefront and its 2005 sequel. It has a mod manager, and you add a mod by handing it the archive the mod came in. Mods get published as .zip, .7z and .rar files, so the manager has to open all three.
RAR was the one that took some work. The engine is released under the GPL, version 3 only, so whatever reads RAR inside it needs a license that’s compatible with that. A mod is also a file a stranger made and somebody downloaded, which is the kind of input I want handled in safe Rust with a ceiling on how much memory and disk it can ask for.
So my company, Centreville Tech, wrote rar-reader and released it free and open source. It’s a Rust library and a small command line tool. It reads RAR archives and can’t create them.
Where the code came from
The decoding logic is libarchive’s. libarchive has two RAR readers, one for RAR 1.5 through 4.x and one for RAR 5, written in C under the 2-clause BSD license. rar-reader is a port of those two files to Rust, at libarchive 3.8.11.
The other pieces have their own sources, and the NOTICE file in the repo lists them file by file:
- The PPMd code is ported from libarchive’s copy of Igor Pavlov’s public domain PPMd variant H, which is based on Dmitry Shkarin’s public domain original.
- BLAKE2s is written from RFC 7693, with the BLAKE2sp tree set up the way libarchive’s bundled reference code does it.
- CRC-32 is the standard one, with no outside code.
No code from the unRAR source, UnRAR.dll, WinRAR or anything else under the unRAR license was used or read. RARLAB’s public RAR 5.0 format note was used only as documentation of the container layout. Every ported file keeps libarchive’s copyright notice.
rar-reader is under the 2-clause BSD license too. That license is compatible with the GPL, so a GPL-3.0-only program can use the library and ship it as long as the notices stay with it. It’s an independent project, with no affiliation with RARLAB, win.rar GmbH or the libarchive project.
How it reads an archive

Opening an archive reads every header in every volume and decompresses nothing. You get the list of entries with names, sizes, times, attributes and checksums, and you extract the ones you want. A set split across .part1.rar, .part2.rar and so on comes back as one archive, and so does the older .rar, .r00, .r01 naming. A self-extracting archive is an archive with a program stuck on the front. rar-reader skips the program and never runs it.
RAR 4 has two compressors, LZSS and PPMd, and an archive can switch between them from one block to the next. RAR 5 has only LZSS. Both formats run filters over the output that undo a transform the packer applied to make things like audio, bitmaps and machine code compress better.
Every extraction is checked against the checksum stored in the archive, and it stops at the size the header declared.
Limits for files you don’t trust
Every size an archive can state is checked against a limit the caller sets. The defaults are 320 MiB of decoder memory, 8 GiB for one entry, 64 GiB written in total, 200,000 entries, 1,000 volumes, and a compression ratio of 4,096 to 1 on entries over 16 MiB.
The crate forbids unsafe code and has no dependencies beyond Rust’s standard library. A damaged archive gets a typed error back. libarchive’s test set includes archives with names like ppmd_use_after_free and distance_overflow, which gives you an idea of what the C readers have been through, and rar-reader’s tests run every one of the damaged ones.
What it doesn’t read
What libarchive can’t read, rar-reader doesn’t read either.
- Encrypted archives are detected and reported, and that’s all. libarchive has no RAR decryption to port, and I didn’t write any for this version.
- In a solid RAR 4 archive it reads the first file and refuses the ones that continue the stream. Solid RAR 5 archives work, in any order.
- The old RAR 1.5 and 2.x compression isn’t read, and neither is the newer compression RAR 7 added.
- RAR 4 lets an archive carry its own filter program. rar-reader runs the five standard ones and refuses any other.
In each case you get an error that names the feature.

The command line tool
The tool is called rar-reader and it has three commands: list, test and extract. Each one takes --json.

extract writes only under the folder you name. It refuses names like ../x, /x and C:x, writes each file under a temporary name, and renames it into place once the checksum matches. Links inside an archive are listed and never created.

How I checked it
A port can go wrong in ways that look fine on the first ten archives, so I tested it four ways.
- Unit tests cover the bit readers, the Huffman tables, the PPMd model, each filter, name decoding, the checksums and the path check.
- libarchive’s own test archives run in CI on Linux, Windows and macOS. For eight of them the tests also try every truncation and 3,000 corruptions each, and nothing is allowed to panic.
- On my own machine I compared it with bsdtar and 7-Zip on 101 archives: libarchive’s test archives plus nine RAR archives of game mods published online, the largest 182 MB unpacked. Of the 226 files inside, 202 came out byte for byte equal to bsdtar’s and 220 equal to 7-Zip’s, and none came out different. The rest are files bsdtar can’t read from the command line or that rar-reader refuses.

The fourth was fuzzing. Six targets feed damaged input to the whole reader and to each part of it by itself. Each target ran for 60 to 90 minutes without a finding, and CI runs all six for 30 seconds on every push.

One gap is written down in the README: the RAR 4 x86 filter has two forms, and the plainer one is unit tested and fuzzed but doesn’t appear in any test archive I have.
How fast it is

On the five archives I timed, rar-reader finished within 0.03 seconds of bsdtar, which is the C code it was ported from. 7-Zip was faster on four of the five, and about twice as fast on the RAR 5 one. Peak memory was 7 MB on the RAR 4 archives and 35 MB on the RAR 5 one, whose header asks for a 32 MiB dictionary.
Those times came from a desktop with other work running, and they moved around between sessions. Compare the three tools on one archive and don’t read much into the differences between archives.
Where to get it
Version 0.1.0 is on GitHub with command line builds for Linux, macOS and Windows. It’s also on crates.io as rar-reader and rar-reader-cli, and it builds with Rust 1.75 or later.
Battlefront Eternal’s movies needed the same treatment, and that became bink-decoder. The rest of what I’ve released lately is for mobile apps and wireless networks: Ti.Socketline, Ti.Paysheet and RESTe 2 for Titanium apps, and a SIM card generator for private LTE and 5G networks.
Do you have a file format nobody on your team wants to touch, or software that has to read one? Send me an email and tell me what it is.
