Introduction
RAR 5.0 is the archive format that WinRAR has written by default since version 5.0 in 2013. It replaced the RAR 1.5 to 4.x format with a new header layout that uses variable-length numbers throughout, so file and archive sizes have no 4 GB limits. It also brought AES-256 encryption, optional BLAKE2sp hashes of the files, larger dictionaries and stronger recovery records. RARLAB publishes the header layout; the compression method is known only through the UnRAR source code.
Multi-volume archives are named name.part1.rar,
name.part2.rar and so on.
Structure
After the signature the archive is a series of blocks. Each block header starts with a CRC-32 of the rest of the header, then the header size, the header type and the header flags, all but the CRC stored as variable-length integers (seven bits per byte, the top bit set when another byte follows). Flags say whether an extra area and a data area follow; a file’s compressed data is the data area of its file header.
0SignatureRar!1A 07 01 008 bytes8Encryption header type 4, only when the headers are encryptedoptional…Main archive header type 1, archive flags such as volume, solid and lockedvaries…File headers and data type 2, each followed by its compressed datarepeated…Service headers type 3, such as comments, NTFS streams and recovery recordsoptional…End of archive type 5varies
A file header holds the file’s flags, unpacked size, attributes, an optional modification time and CRC-32, the compression information (version, solid flag, method and dictionary size), the host operating system and the name in UTF-8. Its extra area can add encryption settings, a BLAKE2sp hash, high-precision times, version numbers and link targets. A self-extracting archive has a program in front of the signature. The reference pages give every field and flag: headers and extra records and services.
Not described
The explorer reads every header, extra record and service header of this page’s format, checks the header CRC-32s and the rules of RARLAB’s technote, and decodes the data of stored and compressed members. What it leaves out is listed here; the RAR page lists the same items with the RAR 4 ones.
Known, not yet covered
- Viewer: the “Password” box decrypts encrypted members and encrypted headers (AES-256-CBC, PBKDF2-HMAC-SHA-256 with the stored salt and rounds, the password check value, and the keyed CRC-32 and BLAKE2sp of files with tweaked checksums, which are then checked). Without a password the encryption fields are shown, the members are listed and not opened, and with encrypted headers only the signature and the archive encryption header can be shown. A wrong password is told by the password check value when the archive has one, else by the header CRC-32 or the member’s CRC-32. Checked on archives built for the test with Node’s AES, PBKDF2 and HMAC, stored and compressed (a compressed member of libarchive’s fixtures re-wrapped), with encrypted headers, and against the PBKDF2 value UnRAR’s source gives; no real archive was opened with a password, because their passwords are not the site’s to type, so no archive written by RAR itself has proved it.
- Viewer: volumes (
name.part1.rar,name.part2.rar…) are joined when the files of the set are handed over together (a dropped folder, or files selected together): a member split over volumes opens whole, checked against the CRC-32 and BLAKE2sp of its last part, and a solid run may cross volumes. The order comes from the names, not from the volume numbers in the headers. A volume opened alone lists a member that continues elsewhere and does not open it. The quick open data and the recovery record of a set are read per volume. - Viewer: the quick open data is checked but not used, and the recovery record is shown but not used to repair the archive.
- Viewer: the dictionary of a RAR 5 archive can be up to 64 GiB (RAR 7.0). The window the decoder holds is the smaller of the dictionary and twice the output of the solid run, so a large dictionary costs nothing when the members are small. Up to 1 GiB the window is one typed array; above that, up to the 1 TB the technote allows, it is a list of 16 MiB pages made as the decoder writes (so the memory held is the smaller of the window and what was written), indexed with ordinary numbers, and distances of 2 GiB and more are followed. A run that would hold more than 8 GiB stops with a message that gives the sizes; a window of pages has no checkpoints, so reading back from the end of such a member decodes again from the start. The packed bytes of the member stay reachable in the tree. Tested on archives built here (a distance just past 2 GiB in a stream with a 4 GiB dictionary, and, on request, one just past 4 GiB with a 16 GiB dictionary and compression version 1’s 80 distance codes); no archive made by RAR 7.0 with such distances was available, and distances of 4 GiB to 1 TB were not reached by a test, only by the same code. A dictionary field above 23 in a version 1 header is reported as a header problem.
Unknown
- Viewer: the data of the ACL and STM service headers is shown as bytes, because their layouts are not published.
Variants
- RAR 5.0 archive (RAR5) – WinRAR’s current archive: CRC-32 block headers with variable-length numbers
- RAR 1.5 to 4.x archive (RAR4) – the older RAR format: blocks with a fixed 7-byte header and 16-bit CRC
Links
Software
- WinRAR – the archiver that makes RAR 5.0 files, with command-line RAR for other systems (Windows, macOS, Linux)
- 7-Zip – free archiver that extracts RAR files (Windows)
- The Unarchiver – free extractor for many formats (macOS)
- PeaZip – free archiver that extracts RAR files (Windows, macOS, Linux)
Developers
- UnRAR source – RARLAB’s extraction code (C++)
- libarchive – reads RAR 5.0 archives among many formats (C)
- rarfile – reads archives with the help of an external extractor (Python)
Reference
- RAR 5.0 archive format – RARLAB’s technical note on the headers