Skip to content

# FAT reader no longer recurses forever into cyclic directories - #810

Merged
Hawkynt merged 1 commit into
mainfrom
fix/fat-cyclic-directories
Nov 10, 2026
Merged

Hawkynt merged 1 commit into
mainfrom
fix/fat-cyclic-directories

Conversation

@Hawkynt

@Hawkynt Hawkynt commented Nov 10, 2026

Copy link
Copy Markdown
Owner

A subdirectory entry pointing back at an ancestor (or itself) made FatReader recurse until the stack overflowed and killed the process. The reader now remembers which directory clusters it has read and does not enter one twice.

Verification

  • FatCorruptDirectoryTests: parent and self cycles crashed the test host before the fix ("Stack overflow") and pass after it; a valid 20-level tree is still fully listed.
  • All 312 FAT tests pass.

Closes #805

Symptom (#805): reading a damaged FAT image killed the process with a stack
overflow (seen on cryptsetup's BitLocker To Go test images, whose zeroed
sectors decrypt to a garbage FAT16).

Root cause: ReadDirectoryEntries descends into every subdirectory entry and
nothing remembered which directories had been read, so a subdirectory whose
start cluster points back at an ancestor - or at itself - was entered again
and again. Cluster chains already had a loop guard; directory recursion did
not.

Fix: track the start clusters of directories already read and skip a
directory that has been visited, keeping the entries read so far.

Verified: new FatCorruptDirectoryTests reproduce the crash (test host
"Stack overflow") before the fix and pass after it, for a parent cycle and a
self cycle; a 20-level valid tree is still listed completely; all 312 FAT
tests pass.

Closes #805
@Hawkynt
Hawkynt merged commit 7c0d2d2 into main Nov 10, 2026
5 checks passed
@Hawkynt
Hawkynt deleted the fix/fat-cyclic-directories branch November 10, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FAT reader overflows the stack on a corrupt FAT16 directory chain

1 participant