You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: EXT4Reader.readFile drops holes: sparse files (e.g. from mke2fs -d) read back short and shifted #979
readFile returns 12288 of 20580 bytes, and the bytes after the hole are shifted. getExtents keeps each extent's physical range but drops its logical block (ExtentLeaf.block). performRead and readFileBytesFromExtents then lay the extents out back to back, so holes vanish, and the tail past the summed extent length is cut off.
We hit this in practice. scripts/build-initfs.sh falls back to mkfs.ext4 -d when no loop mount is available, and the resulting initfs stores /sbin/vminitd sparse (a depth-1 extent tree with gaps). Reading /sbin/vminitd from it gave 92,725,248 of 92,916,784 bytes, and the extracted binary segfaulted on start. debugfs dump of the same file is byte-identical to the built binary.
Images written by EXT4.Formatter are not affected, because it writes zero blocks out rather than leaving holes.
Unwritten extents (ee_len > 32768) are also taken at face value. They should read as zeros.
Expected behavior
readFile returns the file's exact bytes, with holes and unwritten extents read as zeros.
A fix with tests (getFileExtents returns logical block numbers; both read paths zero-fill and place each extent at its logical offset; getExtents keeps its shape for the directory code). It was made against 0.47.0, cherry-picks cleanly onto main, and passes all 64 ContainerizationEXT4Tests on Linux: kunalkushwaha@e870949. Happy to open a PR.
Environment
- OS: Ubuntu 24.04.4 (x86_64), in the swift:6.3.3-noble image
- Xcode: n/a
- Swift: 6.3.3
- e2fsprogs 1.47.0
- containerization 0.47.0; the same code is on main (0cb4d5b)
Relevant log output
✘ Test readFileOfAnE2fsprogsSparseFile() recorded an issue: Expectation failed: (read.count → 12288) == (contents.count → 20580)
Activity