Hi, While working on a enhancement where blocks filled with zeros can be treated as a hole (sparse file), I stumbled upon a bug. I found during mkfs.erofs, the utility handles the sparse files by looking at the holes and marking them as a `erofs_holechunk`. However the calculation of minextblks need to consider the contiguous valid data blocks only else we end up wrongly merging the blobchunks and creating inconsistent erofs image.
This can be easily reproduced with below script which creates a file and punches few holes. $ cat repro.sh #!/bin/bash dd if=/dev/urandom of=sample_sparse_file bs=4096 count=49 fallocate --punch-hole --offset 36864 --length 28672 sample_sparse_file fallocate --punch-hole --offset 143360 --length 53248 sample_sparse_file filefrag -v sample_sparse_file mkdir erofs_image_data cp --sparse=always sample_sparse_file erofs_image_data/ mkfs.erofs --chunksize=4096 problem_erofs.img erofs_image_data/ You can see that if you mount such image, you will have IO errors. $ md5sum mountpt/* md5sum: mountpt/sample_sparse_file: Input/output error The patch addresses this by tracking the start of contiguous data blocks and calculating minextblks correctly. So merging of chunks still happens if possible. Sandeep Dhavale (1): erofs-utils: lib: Fix calculation of minextblks when working with sparse files lib/blobchunk.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) -- 2.44.0.478.gd926399ef9-goog