How Unrar Handles Corrupt Data Across Volumes

When extracting multi-volume RAR archives, corruption that occurs at the boundary between two volumes disrupts the continuous stream required by decompression algorithms. The unrar utility relies on specific volume headers, split-block flags, and cyclic redundancy checks to detect these errors. If the archive lacks error correction data, unrar halts extraction for the affected file at the boundary, though specific command-line flags allow users to salvage partial data up to the point of corruption.

Continuous Streams and Split Headers

In multi-volume archives, large files are compressed as a single continuous byte stream that is arbitrarily cut into predefined block sizes. When a file spans across Volume A and Volume B:

  • The end of Volume A contains a file header flagged with LHD_SPLIT_AFTER (data continues in the next volume).
  • The beginning of Volume B contains a continuation file header flagged with LHD_SPLIT_BEFORE (data began in the previous volume).

Under normal operation, unrar reads to the end of Volume A, prompts for or automatically locates Volume B, verifies the LHD_SPLIT_BEFORE header, and feeds the combined stream into the decompression algorithm (such as LZSS or PPMd) without resetting the sliding dictionary.

Failure Behavior at the Boundary

Corruption spanning the boundary typically affects one of two critical areas: the structural headers or the compressed payload.

  1. Header Corruption: If corruption damages the continuation header at the start of the second volume, unrar cannot verify that the file stream matches the one started in the first volume. It immediately triggers a "Corrupt header" or "Unexpected end of archive" error and stops processing that file entirely.
  2. Payload Corruption: If the headers are intact but the compressed bytes bridging the end of Volume A and the beginning of Volume B are altered or truncated, unrar attempts decompression until the corrupted bytes are processed. Because the decompression dictionary depends entirely on prior byte sequences, corrupted boundary data invalidates the algorithm's internal state. This results in an immediate decompression failure or an output validation mismatch.

Checksum Verification and File Integrity

The RAR format employs integrity checks at multiple stages:

  • Per-block/Volume Checksums: Verifies the validity of the structural blocks.
  • Full-File Checksums: RAR4 uses a 32-bit CRC (CRC32), while RAR5 uses BLAKE2sp or CRC32.

Because file-level checksums are evaluated on the uncompressed stream after extraction completes, boundary corruption causes the final checksum to fail. unrar flags this with a "CRC failed" or "Checksum error" warning and, by default, deletes the partially extracted output file to prevent users from using corrupted data.

Error Recovery and Workarounds

When dealing with boundary corruption, unrar provides specific mechanisms depending on archive options and utility switches:

  • Recovery Records (.rev and built-in records): If the archive was created with Reed-Solomon recovery records, unrar (or the underlying rar repair tool) can reconstruct the corrupted sectors before or during volume transitions, restoring the split stream seamlessly.
  • The Keep Broken Files Flag (-kb): Running unrar x -kb forces the utility to retain whatever partial data was successfully written before the corrupted boundary occurred. However, files that continue past the corrupted boundary into the subsequent volume cannot resume decompression successfully without an intact decompressor state.