How Unrar Handles Mismatched Header CRCs

When extracting files from a RAR archive, the unrar utility verifies the integrity of both the archive structure and the compressed data using Cyclic Redundancy Checks (CRCs). This article explains how unrar detects mismatched header CRCs, its default failure response, and the specific mechanisms or commands available to bypass corrupted headers and salvage salvageable data.

The Role of Header CRCs in RAR Archives

Every RAR archive is organized into structured blocks, such as archive headers, file headers, and service headers. Each header contains essential metadata, including the file name, compression method, uncompressed size, and host OS attributes. Crucially, each header block includes a dedicated CRC32 checksum calculated strictly across the header fields themselves, distinct from the file data CRC.

When unrar parses an archive, it reads the header block, recalculates the checksum over the header's bytes, and compares the result to the stored header CRC value. If the calculated value does not match the stored checksum, unrar flags the header as corrupt.

Default Behavior on CRC Mismatch

By default, unrar treats a header CRC mismatch as a fatal structural error. Because a damaged header may have corrupted pointers, invalid file sizes, or falsified block lengths, trusting the header could cause the extractor to read arbitrary memory, write to invalid filesystem paths, or enter infinite loops.

Consequently, unrar takes the following default actions:

  1. It halts processing for the affected file or block.
  2. It outputs an error message, typically stating: Corrupt header is found or Header CRC mismatch.
  3. It aborts the extraction process or skips to the next recognizable block, depending on the severity of the damage.

Recovery and Scanning Mechanisms

When encountering an invalid header, unrar attempts to handle the corruption through specific recovery paths:

  • Signature Scanning: If a block header is unreadable, unrar attempts to resynchronize with the archive stream. It scans forward byte-by-byte looking for standard RAR marker signatures (such as 0x74 for a file header block). If it finds a valid marker followed by a valid header CRC, it resumes extraction from that point forward, effectively dropping only the damaged header.
  • Using Recovery Records (rar r): If the archive was generated with built-in recovery records (using Reed-Solomon error correction), unrar cannot fix the header on the fly during extraction. Instead, the user must run the repair command via RAR (rar r damaged.rar). This process reconstructs the corrupted sectors—including header blocks—and produces a new fixed.rar archive where header CRCs match correctly.
  • Keeping Broken Files (-kb): While the -kb (Keep Broken) switch is primarily designed for data CRC mismatches, it also instructs unrar not to delete partially unpacked files if an error terminates the process prematurely. If the header itself is valid enough to initiate extraction but a trailing header or block CRC fails, -kb ensures that extracted bytes remain on the disk.