Diagnosing and Repairing Damaged Archives: Read the Error First
Table of Contents
An archive that refuses to open hands you an error message, and that message is the best evidence you have. A CRC failure means the container was read and the payload inside it was not. A missing end-of-central-directory record means the opposite: the data may be perfect and the map to it gone. The two faults need different tools, and the wrong one can finish the job the corruption started.
What a CRC error actually reports
Every ZIP entry carries a CRC-32 value: a 32-bit checksum of the file after decompression, written in the local header and in the central directory. When unzip prints bad CRC or 7-Zip reports Data Error, the entry has already been found, its stream decoded and the result compared against that value. The comparison failed, so the bytes that came out are not the bytes the compressor put in.
A CRC is a detector, not a corrector. It says the payload is wrong without saying where, and cannot rebuild it. Corruption at rest, from a bad sector, and corruption in transit look identical here. What you do know is that the structure survived: signatures found, headers parsed, stream decoded to the end.
Header damage and data damage are different failures
An archive has two independent layers. The first is structural: signatures, per-entry headers, name tables and the index. The second is the compressed payload. A fault in the first produces The archive is either in unknown format or damaged, or 7-Zip's Cannot open file as archive, because entries cannot be located. A fault in the second produces a CRC mismatch on one entry while the rest lists and extracts without complaint.
Header damage is often repairable. Headers are small, patterned and partly redundant, which is why a tool can rescan for the PK\x03\x04 signature that opens each ZIP entry and rebuild an index. Payload damage is different: a compressed stream cannot be decoded from the middle, because the decoder needs every earlier byte. In ZIP each entry is compressed separately, so damage stays local. In a solid RAR or 7z block, one damaged region can take every file stored after it.
A file that fails to open has not necessarily lost data, and a file that opens cleanly has not necessarily kept it. Identify the failing layer before writing anything to the damaged copy.
Why a ZIP keeps its index at the end
A ZIP is written front to back but read back to front. Each entry is appended with its local header and compressed data as it arrives, and the central directory, with offsets, sizes and CRCs, is written last. It is followed by the end-of-central-directory record: 22 fixed bytes plus an optional comment of up to 65,535 bytes. A reader looks for that record first: it says where the directory begins.
The layout lets a tool append to a 4 GB archive without rewriting it, and explains why truncation hurts. Cutting the last few kilobytes removes the EOCD and the directory with it, so unzip reports End-of-central-directory signature not found while every compressed byte is still on disk. Nothing was lost except the map.
zip -F trusts the surviving directory and copies what it can read. zip -FF ignores the directory and scans forward for entry signatures. That scan is what makes -FF right for a truncated file, and what makes its output less trustworthy: where data is ambiguous, it can invent boundaries.
Recovery commands that never touch the original
None of these should run against your only copy. Work on a duplicate.
sha256sum broken.zip > broken.sha256sumrecords the original state, so you can prove it was never modified.- Test instead of opening:
unzip -t broken.zip,7z t broken.7z,unrar t broken.rarandzstd -t archive.tar.zstreport per entry instead of stopping at the first error. - Rebuild the index with
zip -FF broken.zip --out fixed.zipand confirm withunzip -t fixed.zip. Use-Fwhile the directory still reads. 7z x broken.7z -o./out -ymoves to the next entry after a data error;unrar x -kb broken.rarkeeps damaged output instead of deleting it.unrar r broken.rarwritesfixed.broken.rarwhen a recovery record exists. Without one it can only rebuild structure, asrebuilt.broken.rar.zstd -dc archive.tar.zst > partial.tarkeeps the prefix before the cut;tar -tf partial.tarlists what survived.
What each format can actually give back
The table separates three things that get confused: where the index lives, what truncation destroys, and what can be reconstructed.
| Format | Index location | Effect of truncation | Command | Realistic outcome |
|---|---|---|---|---|
| ZIP | EOCD record at the end | Directory lost, entry data intact | zip -FF | Most entries recovered, unreadable ones dropped |
| 7z | 32-byte start header, compressed header at the end | Header lost, streams intact | 7z x | Entries found by scan, names and sizes unreliable |
| RAR5 | Headers interleaved with data, optional RR | Last files lost, RR covers one continuous damaged area | unrar r | Complete with recovery record, intact files otherwise |
| tar + gzip or zstd | None, purely sequential | Only the tail is lost | zstd -dc or gzip -dc | Every member written before the cut |
ZIP is the only format here whose index can be rebuilt from the data itself, and the worst when the file end vanishes. The trade-off is deliberate: the format lets one archive be patched without rewriting the file.
Repair saves data, it does not certify it
Repaired bytes are new bytes. A tool that resynchronises on signatures, patches parity blocks or stitches a partial stream produces a file that no longer matches what was published. Its SHA-256 will differ from the published checksum even when every recovered file inside is correct, so a mismatch after repair proves nothing.
Verify at the level that matters. Extract, hash each recovered file and compare against a per-file manifest published with the release. When the only reference is the container hash, check content instead: the file opens in the application that owns the format, its size matches its header, and its sidecar checksum matches if one exists. The checksum verifier computes SHA-256 locally, enough to compare two copies of the same extracted file.
Repair to recover data, verify to trust it. A repaired file that has never been hashed is a guess with good manners. For the format-level background, the comparison of archive formats explains where each one keeps its index and checksums.
Troubleshooting Common Issues
| Error / Issue | Technical Cause | Step-by-Step Fix |
|---|---|---|
| bad CRC (unzip) or CRC failed in report.xlsx, the file is corrupt (WinRAR) | The stored CRC-32 does not match the decompressed data. The entry header was read correctly, so the container is intact and the payload is not. | Transfer the file again before repairing anything. If the same entry fails twice, the stored copy is damaged: extract the remaining entries and discard this one. |
| End-of-central-directory signature not found | The archive was truncated, so the central directory and the EOCD record at the end of the file are missing. | Run zip -FF broken.zip --out fixed.zip. It scans forward for entry signatures instead of trusting the index, which is the only route left when the tail is gone. |
| Cannot open file as archive (7-Zip) | The 32-byte start header no longer points to a valid compressed header, usually because the file was cut short or the first sectors changed. | Try 7z x on a copy and accept partial output. If no entry is listed, the header is gone and a fresh transfer is the only reliable fix. |
| zstd: archive.tar.zst: unexpected end of file | The zstd frame ends before its declared content, which happens whenever a transfer stops early inside the last block. | Decompress to stdout with zstd -dc and keep the prefix that decodes, then list the tar members you recovered with tar -tf. |
Frequently Asked Questions
Does a CRC error mean the whole archive is unusable?
No. The CRC is stored per entry, so a single mismatch points at one file inside the container. Every other entry can extract normally, and a repair tool will copy them into a new archive while dropping the failed one.
Can zip -FF recover a ZIP whose last kilobytes are missing?
Usually yes. The scan walks forward through the local headers and rebuilds an index, so entries whose data is complete come back intact. Entries cut by the truncation return damaged, and file names taken from partial headers can be wrong.
Is unrar r the same as the Repair button in WinRAR?
They run the same two-stage routine. Stage one uses the recovery record and writes fixed.archive.rar. Stage two only rebuilds the structure, writes rebuilt.archive.rar, and cannot restore files that fail their checksum.
Why does a repaired archive have a different SHA-256?
Because the bytes are new. Rewritten headers, a fresh index and different timestamps change the file hash even when every payload is identical. Compare hashes per extracted file, not on the repaired container.
Related Technical Guides
Choosing an Archive Format: Ratio, Speed and Compatibility
DEFLATE, LZMA2 and Zstandard compared by content type: realistic ratios, dictionary memory, solid blocks, header encryption and hash drift.