When do two Korean filenames in a ZIP become one after NFC normalization?
A ZIP from a supplier contains two files with names that look identical. Before deleting one or normalizing both names, check whether their full archive paths would match after normalization.
Two entries in the same folder converged on one name in our test. The same pair in different folders did not.
01 Β· Why does one name take 19 bytes or 37 bytes?
The Korean part of κ±°λλͺ
μΈμ.txt can be represented as precomposed Hangul syllables or as sequences of individual jamo. Unicode normalization gives canonically equivalent text a consistent representation.
In this example, NFC uses precomposed syllables and NFD uses decomposed jamo. A renderer can display both forms alike even when software compares different strings.
With the extension included, the two forms took 19 and 37 UTF-8 bytes, and both normalized to the same NFC string. Those counts are filename lengths, not ZIP sizes.
Unicode normalization standard Figure 1. The sample filename takes 19 UTF-8 bytes in NFC and 37 in NFD. Applying NFC to both yields the same string.
02 Β· Compare the same folder with different folders
We created two synthetic ZIPs with Python 3.12.14 (Unicode database 15.0.0) on cloud Linux. In each ZIP the two file entries contained the ASCII bytes A and B respectively. The only changed condition was whether the entries shared a folder.
Without extracting anything, we applied NFC to each recorded full file path and counted the distinct results.
| Input | Original file entries | Distinct full paths after NFC | Result |
|---|---|---|---|
| Same folder: one NFC name and one NFD name | 2 | 1 | NFC introduces a collision |
| Different folders: the same names under a/ and b/ | 2 | 2 | NFC alone introduces no collision |
Each archive's SHA-256 was unchanged by the scan. No file disappeared during the test. The scan predicted where bulk renaming would produce the same path.
Comparing basenames alone would wrongly flag the different-folder case. Figure 2. Two entries in the same folder converge on one NFC path; different parent folders preserve two distinct paths.
03 Β· Reproduce without extracting anything
This script writes synthetic ZIPs only to a temporary directory and removes them on exit. It does not write to or extract an existing archive. The read-only scan(path) groups full file paths by their NFC form.
The expected output is 19 37, followed by same-folder 2 1 unchanged and different-folders 2 2 unchanged.
For a work archive, keep a copy and inspect groups containing two or more entries before deciding on new names.
Python zipfile documentation
from collections import defaultdict
from hashlib import sha256
from pathlib import Path
from tempfile import TemporaryDirectory
from unicodedata import normalize
from zipfile import ZipFile
def scan(path):
groups = defaultdict(list)
with ZipFile(path) as z:
for item in z.infolist():
if not item.is_dir():
groups[normalize("NFC", item.filename)].append(item.filename)
return groups
a = "κ±°λλͺ
μΈμ.txt"
b = normalize("NFD", a)
print(len(a.encode("utf-8")), len(b.encode("utf-8")))
with TemporaryDirectory() as tmp:
for label, paths in [
("same-folder", (a, b)),
("different-folders", ("a/" + a, "b/" + b)),
]:
path = Path(tmp) / (label + ".zip")
with ZipFile(path, "w") as z:
z.writestr(paths[0], b"A")
z.writestr(paths[1], b"B")
before = sha256(path.read_bytes()).hexdigest()
groups = scan(path)
after = sha256(path.read_bytes()).hexdigest()
print(label, sum(map(len, groups.values())), len(groups), "unchanged" if before == after else "changed")
04 Β· Resolve name collisions before renaming
If the same NFC path groups files with different contents, keep both originals and choose distinct names that identify the actual documents or versions.
Two distinct NFC paths do not prove an archive is safe to extract. This experiment does not test case folding, OS-reserved names, directory entries, path traversal, legacy ZIP filename encodings, or extractor overwrite behavior. It does not test extraction on macOS or Windows.
If the problem concerns names of files you have already extracted, keep the originals and preview new names and duplicates first. This Korean filename-repair guide covers individual files. Renaming the ZIP as a single file changes the archive's outer name and leaves the names inside unchanged.
Comments
No comments yet. Start the discussion.