The Lying Header: All 900 Fields Decode, and All 900 Come Out Wrong
A file header that names an encoding is making a factual claim about the bytes that follow it, and readers trust that claim completely. In this test...
A file header that names an encoding is making a factual claim about the bytes that follow it, and readers trust that claim completely. In this test the claim was false for every field in the file. Nine hundred text fields were declared as one encoding while actually written in another, and a reader that followed the declaration leniently produced output for all 900 of them — with all 900 damaged. No crash announced the problem, because the lenient reader's job is precisely not to crash. A stricter reader refused, loudly, for most of two groups and not at all for the third. A fallback reader that tested the bytes themselves repaired most of the file, except in one group, where it stopped at the wrong encoding and left over half the group wrong while believing it had succeeded.
What The Lying Header means
The Lying Header means a mismatch between the encoding a file declares for itself and the encoding its bytes are actually written in, together with the damage that follows when readers act on the declaration instead of the bytes. Every text field carries two facts: the byte sequence itself, and a label saying how those bytes should be decoded. When the label is accurate, the distinction is invisible. When it lies, the reader faces a fork. Decode strictly by the label and the read may fail outright. Decode leniently and the read succeeds into gibberish — replacement characters where decoding broke, or plausible-looking wrong characters where it did not. The data has not changed. Only the instruction for reading it is false, and that is enough to corrupt every field while leaving the file structurally perfect.
This concept differs from the Mojibake Rate examined in an earlier batch. That measure counted a decode failure rate: how often text written in one encoding, read as another, produced garbled output — a property of a byte-level mismatch. The Lying Header is about the declaration layer above that mismatch. Its variables are the false label itself, the difference between strict and lenient obedience to it, and the repair rate of a reader that disregards the label and interrogates the bytes. The practical question is not whether two encodings garble each other in principle, but whether the metadata a pipeline trusts is telling the truth, and what happens, group by group, when it is not.
Nine hundred fields, three directions of falsehood
The test file held 900 text fields in three groups of 300, covering three directions a declaration can be wrong. In the first group, the bytes were written in Latin-1 while the file declared UTF-8. In the second, the bytes were written in GBK while the file declared UTF-8. In the third the lie ran in reverse: the bytes were genuine UTF-8, while the file declared Latin-1. The groups matter because the same falsehood behaves differently by encoding. Some encodings reject foreign byte sequences outright. Others accept almost anything and produce characters, the more dangerous outcome: a rejected field can be quarantined, while an accepted-but-wrong field flows downstream as if it were data.
A lenient reader that followed the declaration damaged 900 of 900 fields, a mojibake rate of 100%. Between them the damaged fields contained 4,591 wrong characters. The Latin-1 group contributed 900 of those characters, the GBK group 1,746, and the reverse group 1,945. The reverse group's figure deserves a pause. Its bytes were valid UTF-8 all along; nothing was wrong with the data at all. Decoded as Latin-1, as the false declaration instructed, every multi-byte character split into separate Latin-1 characters, and the field filled with accented debris. A perfect file, mislabelled, produced the largest error count of the three groups.
Strict refusal, and the reader that stopped too early
A strict reader that followed the same declaration, but refused rather than replaced, failed on 300 fields in the Latin-1 group — every one of them — and on 298 fields in the GBK group. Those refusals are the problem at its most visible: hundreds of hard errors, an import that stops, an operator who knows something is wrong. In the reverse group, strict decoding failed on 0 fields, because Latin-1 decoding accepts every possible byte. Strictness, which protected two groups by shouting, protected the third not at all; it passed 300 quietly garbled fields as valid. Whether a lying header produces an alarm or a silent corruption depends entirely on whether the declared encoding happens to be one that can refuse.
The final reader ignored the declaration and worked from the bytes, trying strict UTF-8 first, then strict GBK, then Latin-1, with an additional re-encoding retry for fields under the reverse lie. It repaired 734 of 900 fields, which is 81.56%. The GBK group recovered almost completely, at 298 of 300, and the reverse group in full, at 300 of 300. The Latin-1 group, however, recovered only 136 of 300. The reason is a trap inside the fallback chain. Latin-1 byte sequences very often form sequences GBK can decode strictly, into unrelated but valid characters. The reader reached its GBK step, the bytes decoded without error, and it stopped, satisfied, holding text that was formally valid and actually wrong. Strict success at the wrong encoding is indistinguishable, from inside the chain, from strict success at the right one. That is why the honest headline figure of 81.56% conceals a group where the repair mostly failed while reporting success.
How this was measured
The fields in this exercise were synthetic text, assembled by the measurement script itself into the three groups described above, each encoded in bytes that contradicted the declaration the script attached to the file. The script ran with its seed fixed at 42, so the same fields are produced on every rerun. The strict, lenient and fallback readers were all implemented as the script's own deterministic logic, applied identically to all 900 fields, and the fallback reader chose its encoding purely from decoding behaviour, never from knowledge of which group a field belonged to. The exercise measures how declaration mismatches behave on constructed data. It is not a benchmark of any commercial import tool or data platform, and no vendor product was evaluated.
Questions, answered
How many fields survived a lenient read by the declared encoding? None. The lenient reader produced damaged output for 900 of 900 fields, a mojibake rate of 100%, with 4,591 wrong characters in total: 900 in the Latin-1 group, 1,746 in the GBK group and 1,945 in the reverse group. Lenient decoding guarantees output, and here it was wrong everywhere.
Why did strict decoding fail on 300 and 298 fields, but on none in the third group? Because refusal depends on the declared encoding, not on the truth. Declared as UTF-8, the Latin-1 bytes failed 300 times and the GBK bytes 298 times, since those sequences are mostly not valid UTF-8. Declared as Latin-1, the reverse group failed 0 times, because Latin-1 accepts every byte value. The healthiest bytes received the least protection.
How well did the fallback reader do, and where did it fall short? It repaired 734 of 900 fields, or 81.56%, including 298 of 300 in the GBK group and 300 of 300 in the reverse group. It fell short in the Latin-1 group, repairing only 136 of 300, because Latin-1 bytes frequently decode strictly as GBK into unrelated characters, so the chain stopped at the wrong encoding.
Can a successful strict decode be trusted as proof of the right encoding? No, and the Latin-1 group's repair rate is the demonstration. A strict decode proves only that the bytes are legal in the attempted encoding. Where two encodings overlap enough for foreign bytes to be legal, as Latin-1 bytes are under GBK, the proof is hollow. Legality is a property of the byte sequence; correctness is a property of the match between bytes and their true encoding.
Summary
A declaration that lies about encoding corrupted 900 of 900 fields under a lenient read, scattering 4,591 wrong characters, while strict reading refused 300 fields in one group, 298 in another and none at all in the group whose declared encoding cannot refuse. A fallback reader that trusted bytes over labels repaired 734 of 900 fields, 81.56%, yet left the Latin-1 group at only 136 of 300, stopped early by decodes that were valid and wrong. The Lying Header teaches a layered distrust: treat declarations as claims to be tested, lenient output as suspect by default, and even a strict decoding success as evidence to weigh, not as a verdict.
Sources
- SmartDataAI import test W6 (declared versus actual encoding), run on 2026-11-23 — script and output JSON are in this batch's evidence folder.
- Construction note: the script built all three groups itself under a fixed seed, attached the false declarations, and ran each reader over the identical file.