How Unrar Handles Zero-Byte Files in Archives
This article explains how the unrar utility processes
zero-byte (empty) files stored within RAR archives. It covers the
internal mechanics of RAR archive headers, the extraction workflow
executed by unrar, how system attributes and timestamps are
applied without running decompression algorithms, and how file integrity
verification behaves with empty payloads.
Storage of Zero-Byte Files in RAR Headers
In the RAR format specification, every file entry begins with a file header block containing metadata such as the file name, original file size, compressed file size, operating system attributes, and cyclic redundancy check (CRC) values.
When an empty file is added to a RAR archive:
- Both the uncompressed size and compressed
size fields are set to
0. - The archive allocates space strictly for the header block; no data blocks or compression streams follow the header.
- Depending on the RAR format version (RAR4 vs. RAR5), the checksum for the data payload is either set to zero or evaluated against a zero-length byte sequence, resulting in a predictable, standardized checksum value.
Extraction Mechanics in
unrar
When unrar extracts an archive containing an empty file,
it bypasses the decompression engine entirely. The extraction process
follows these specific steps:
- Header Parsing:
unrarreads the file header block and identifies that the uncompressed size is0. - File System Call: The utility issues a standard
system call (such as
open()withO_CREAT | O_WRONLY | O_TRUNCon POSIX systems, orCreateFile()on Windows) to create the destination file on the disk. - Payload Bypass: Because the compressed size is
zero,
unrardoes not invoke any decompression routines (such as the LZSS or PPMd algorithms). It writes zero bytes of content to the target file. - Metadata Application: Before closing the file
descriptor,
unrarapplies the stored attributes, access permissions (on POSIX systems), and last-modified timestamps specified in the file header. - Descriptor Closure: The file handle is closed immediately, leaving a valid, zero-byte file on the destination filesystem.
Integrity Verification
(unrar t)
When running unrar t to test archive integrity,
unrar does not attempt to decompress non-existent data
blocks. Instead:
- It validates the structural integrity of the file header itself using the header's own CRC/checksum.
- It verifies that the declared compressed and uncompressed sizes are both zero.
- The test passes as valid without checking or reporting errors on the missing payload, marking the entry as successful.
System-Level Considerations
- Inode and File Table Usage: While zero-byte files
consume
0bytes of actual disk space, their extraction byunrarconsumes a filesystem inode (on Unix-like systems) or a Master File Table (MFT) record (on NTFS). If an archive contains millions of empty files, extraction can fail due to inode exhaustion even if storage space remains abundant. - Overwriting Behavior: When extracting with
overwrite flags enabled,
unrarwill truncate an existing file of any size down to zero bytes to match the archive entry. If run in interactive mode, it prompts the user before replacing an existing non-empty file with an empty one.