1. Peel
  2. The Pith
  3. When a bit goes wrong
Essay · Security

What Happens When a Single Bit Goes Wrong?

Measuring how compressed data fails.

By · · Updated · The Pith, no. 6 · 7 min read

A mosaic of orange, cream and dark tiles with one tile displaced

Imagine an archive containing ten thousand photographs. Somewhere inside that archive, one bit changes. A zero becomes a one. The file is the same size, its name hasn’t changed, and the operating system may have no reason to suspect anything is wrong.

How much information have we lost? One bit? One photograph? Everything that follows it?

Those are very different outcomes, and none can be determined from the number of damaged bits alone. What matters is the role that bit plays in the representation and the dependencies that connect it to everything else.

In the previous articles we considered how to represent information efficiently and how to measure the performance of that representation. Here I want to examine what happens when the representation stops being correct.

One bit is not necessarily one bit of damage

In an uncompressed byte array, a single bit flip changes one byte. The remaining bytes are still available at their original offsets. That does not mean the application can necessarily use them: a damaged length field or instruction may have consequences far beyond that byte. But the storage representation itself has not shifted.

Compressed streams introduce additional dependencies. A bit might participate in a literal symbol, a length, a dictionary reference or a coding decision. In a variable-length code, changing one bit may alter how subsequent bits are interpreted. A damaged reference can reproduce incorrect data and later references can reproduce that error again.

There is no universal rule that a bit flip destroys the remainder of a compressed file. Some errors are localized, some change the interpretation of a larger region, and some affect only metadata. The codec, the position of the error and the decoder’s validation behavior determine the result (Figure 1).

Fig. 01 / Interactive

Flip a bit.

Choose one bit of the ASCII byte for A (65). Each button flips one bit.

Figure 1. Real binary arithmetic on a raw byte, not a compressed stream.

Detection isn’t recovery

A checksum is a compact description of a message used to detect inconsistencies. A CRC is particularly useful for detecting accidental corruption. The gzip format, for example, stores a CRC-32 of the uncompressed data and its size modulo 2³² in the member trailer. ZIP commonly records a CRC-32 for each entry.

When a checksum doesn’t match, the decoder has evidence that something is wrong. It has not necessarily learned which bit changed, nor how to reconstruct the original data. CRCs have mathematical error-detection properties, but collisions exist and CRCs are not cryptographic authentication.

Consider a very small illustrative checksum: the XOR of three bytes. Changing a single bit in one byte changes the checksum. Changing the corresponding bit in two bytes leaves it unchanged. This is deliberately weaker than CRC-32, but it demonstrates why detecting damage and recovering information are different requirements (Figure 2).

Fig. 02 / Interactive

A checksum can miss changes.

Bits to flip
Figure 2. A teaching example using XOR, not the CRC-32 algorithm. The expected checksum stays fixed at the original value.

Where does the damage stop?

In an archive, the boundaries between independently decodable units matter. Imagine three blocks, each containing one megabyte of original data. Each block has its own checksum and can be decoded without the others. If the middle block is corrupted, the first and third may still be recovered and validated, provided their offsets and necessary metadata survive.

Now imagine the same three blocks encoded as a dependent stream. A later block might reference earlier decoded bytes or require coding state carried forward from an earlier block. Even when the later bytes are physically intact, they may no longer be usable without reconstructing the state on which they depend.

Solid archives can improve compression by sharing context across files. The price of that choice may include increased retrieval work and larger failure domains. Solid does not necessarily mean one uninterrupted dependency chain across an entire archive: formats and implementations can provide restart points or multiple solid blocks (Figure 3).

Fig. 03 / Interactive

Choose the damaged block.

Verifiable Damaged Unverified

Figure 3. A conservative conceptual model: eight equal 1 MiB blocks with intact offsets and metadata. Purple blocks are unverified, not proven destroyed. Real codecs can behave differently.

Sometimes redundancy is exactly what we need

Compression and error correction pursue different objectives. Compression exploits redundancy to reduce representation cost. Error correction introduces deliberate redundancy to make the representation more resilient.

Suppose we store three equal-length blocks and a fourth parity block calculated by XORing the first three. If we know which one of the original blocks is missing, we can reconstruct it by XORing the remaining two with parity. This simple scheme can recover one known erasure, not arbitrary unknown corruption. More sophisticated error-correcting codes extend this capability under explicit assumptions (Figure 4).

Fig. 04 / Interactive

Reconstruct a missing byte.

Figure 4. A real XOR reconstruction of one known erasure. The other bytes and the parity byte are assumed intact.

Recovery records consume storage, and that overhead is worth accounting for in a compression benchmark. A format that produces a slightly larger archive but allows verified recovery under defined damage conditions may be preferable for long-term preservation.

When refusing to decode is the correct result

Authenticated encryption adds another consideration. A correctly implemented authenticated encryption scheme verifies the authenticity of a protected unit before releasing it as trusted plaintext. A damaged ciphertext or authentication tag may cause the entire unit to be rejected. That is a security property, not necessarily a defect in the recovery implementation.

Encryption without authentication does not provide the same assurance. Checksums, authentication tags and recovery records serve distinct purposes; one should not be presented as a substitute for another.

For an archive utility, it is important to communicate the difference between a file that could not be decoded, a file that decoded but failed integrity validation, and a file that has been independently verified. Recovering bytes is not the same as recovering trustworthy information.

A small experiment in failure

To make this concrete, I generated a gzip member from a short synthetic text fixture and flipped each of its bits individually, always starting from the original member. Each mutated copy was passed to a bounded zlib decoder. The decoded bytes were compared with the known original. The experiment does not evaluate Peel or Rind, and it does not establish general probabilities of archive failure.

The fixture contains 528 bytes and its complete gzip representation contains 59 bytes. We tested 472 mutations, including header, DEFLATE stream and trailer. Figure 5 shows the eight possible single-bit mutations at each byte offset.

Fig. 05 / Measured

One byte, eight possible failures.

Exact original output Different completed output Rejected or incomplete

Figure 5. Measured with Python 3.13.5 and zlib 1.3.1, and reproduced exactly with Python 3.13.18 and zlib 1.2.12. Each trial is bounded to 8,192 output bytes; completion requires end-of-stream and no unused bytes. The results are specific to this fixture.

Across this fixture, 56 mutations returned the original bytes, 0 produced different completed output, and 416 were rejected or did not meet the completion criteria. An unchanged output is possible when the mutation affects information that does not change the decoded payload, such as some header fields. This does not establish that all metadata remained correct.

Notice what we are measuring: exact reconstruction of a known payload. A successful decoder return alone would not have been sufficient. Conversely, a decoder error does not establish that every original byte is irrecoverable; it establishes that this decoding procedure did not return a complete accepted member.

To reproduce it:

import gzip, zlib
          from collections import Counter
          data = b"Peel: information has structure.\n" * 16
          encoded = gzip.compress(data, mtime=0)
          counts = Counter()
          for i in range(len(encoded)):
              for bit in range(8):
                  mutated = bytearray(encoded)
                  mutated[i] ^= 1 << bit
                  try:
                      d = zlib.decompressobj(31)
                      out = d.decompress(mutated, 8192)
                      if not d.eof or d.unused_data:
                          counts["rejected"] += 1
                      elif out == data:
                          counts["exact"] += 1
                      else:
                          counts["different"] += 1
                  except zlib.error:
                      counts["rejected"] += 1
          print(counts)

Input SHA-256: e854575aff3f84ced71288aa496c1b6f94bd9da9409610f3edaf04c94c2464c8

What should a recovery benchmark report?

I’d separate detection, reconstruction and verification into distinct measurements. A benchmark should identify the damage location and kind, the affected archive structure, the decoder version, the recovery procedure, and the original data against which the recovered output was checked.

Measurement What it establishes
Verified recovered bytes Original bytes reconstructed at their correct locations and checked against a known reference
Detected failure Decoder or integrity validation rejected an affected unit
Silent corruption Output accepted by the evaluated procedure but differs from the reference
Unverified output Bytes returned without sufficient evidence of correctness
Recovery overhead Additional storage, processing time and memory required for recovery

For mixed archives, I’d also report verified file counts, metadata preservation, and the distribution of recovery outcomes by damage location. An archive containing one enormous file and thousands of tiny ones can look quite different depending on whether we aggregate by bytes or by entries.

A proper experiment would compare independently compressed entries, solid blocks, different restart intervals, and formats with optional recovery records. The input data and mutation schedule should be versioned and retained. Every run should use a fresh copy of the fixture, bounded resource usage, and a controlled environment.

The cost of losing information

While working on archive software, it’s tempting to focus on how quickly we can encode information, how small the representation becomes, and how quickly we can access it again. Those are important measurements. They don’t tell us what happens after the representation has been damaged.

For Rind and Peel, I would like recovery behavior to be as measurable as compression performance. Not a promise that damaged archives can always be repaired, but an explicit account of what can be recovered, under which conditions, and how confidently we can verify it.

One bit may be insignificant. It may also be the bit that determines whether an entire region of information can be interpreted. The difference is in the structure of the representation.

Compression tells us how economically we can describe information. Recovery tells us how much of that description we can afford to lose.

References and further reading

Research disclosure: Figure 5 reports a completed, bounded experiment on one synthetic gzip member. Figures 1, 2 and 4 are calculated examples; Figure 3 is a conceptual model. No production archive recovery results or claims about Peel or Rind are made. References are specification links, not a fresh literature review.

Read next · No. 08 · EngineeringWill We Be Able to Open Today’s Files in 100 Years?Detecting damage is the short game. Keeping files readable for a century means keeping their decoders and keys alive too.
Peel's icon: an orange on a cream tile

Get Peel. Free forever.

No account, no ads, no trial. Everything Peel does today stays free, and it keeps itself up to date.

Download Peel 1.4.0 brew install --cask snackstudio/tap/peel
Requirements
macOS 13 Ventura or later, on Apple silicon or Intel.
Install
Open the installer and follow it. Or open the disk image and drag Peel to Applications, or run brew install --cask snackstudio/tap/peel in Terminal.
Updates
Peel updates itself, and every update is signed. To check now, choose Peel ▸ Check for Updates…
Uninstall
Drag Peel to the Trash, or run brew uninstall --cask peel.
Price
Free. No account, no ads, no trial.
Privacy
Your files never leave your Mac, and the app has no analytics. This site counts visits to learn what helps; the privacy policy says how.