How Unrar Processes Missing Archive Headers
This article explains how the unrar utility detects,
navigates, and attempts to recover from missing or corrupted headers
within RAR archive files. When critical metadata structures are absent,
unrar relies on a combination of header signature scanning,
error-correction data, and fault-tolerant extraction flags to salvage
accessible data.
RAR Header Architecture and Failure Detection
RAR archives are organized as a sequential stream of discrete blocks,
including the Main Archive Header, File Headers, and Service Headers.
Each block begins with specific magic bytes, a header type identifier,
and a Cyclic Redundancy Check (CRC32 or BLAKE2sp in RAR5) that validates
the header's integrity. When unrar encounters a byte stream
where expected header signatures or checksums do not match, it
identifies that a header is either corrupted or entirely missing. By
default, sequential processing stops, and the utility outputs a "Corrupt
header" or "Unexpected end of archive" error.
Recovery Record Processing
If the archive was created with an optional recovery record,
unrar can mathematically reconstruct missing headers. The
recovery record utilizes Reed-Solomon error-correcting codes distributed
across dedicated recovery sectors. During processing, unrar
reads the intact recovery data to recalculate the missing bytes
belonging to the damaged header block, restoring file attributes, names,
and offset tables before proceeding with extraction.
Resynchronization via Signature Scanning
When no recovery record is available, unrar attempts to
resynchronize its position within the archive file. Instead of
terminating immediately, the extraction engine moves forward
byte-by-byte through the binary stream searching for the next
recognizable file header signature.
- In RAR 4.x archives, it searches for the standard
0x74file header marker. - In RAR 5.x archives, it scans for the specific variable-length header markers defined in the modern specification.
Once a valid header signature with a matching checksum is located,
unrar resumes extraction from that offset. Any file data
that depended on the missing header is lost or skipped, but subsequent
files with intact headers can still be read.
Manual Overrides and Partial Extraction
Because missing headers prevent unrar from determining
exact file boundaries and decompression parameters, extraction normally
aborts to avoid outputting garbage data. However, command-line arguments
alter this behavior:
- The
-kb(Keep Broken) switch: Instructsunrarnot to delete partially extracted files upon encountering an error, preserving whatever data was processed before the missing header was reached. - The
r(Repair) command: Forces an automated scan of the archive to locate all valid headers, reconstruct missing structural tables where possible, and output a rebuilt archive (fixed.rar).