Previous to this commit calling map_file_extents on an effectively
empty file (either true zero size or an empty sparse file) caused
genimage to segfault.
This is a consequence of FS_IOC_FIEMAP returning 0 mapped extents for
effectively empty files. map_file_extents relies on
number of mapped extents > 0 wihtout ever checking it, resulting in
an integer underflow and subsequent segfault due to an out of bounds
memory access.
This commit fixes the issue by checking the number of mapped extents
is not 0 before trying to access the last extent.
Previous to this commit calling
map_file_extents
on an effectively empty file (either true zero size or an empty sparse file) caused genimage to segfault. This is a consequence of FS_IOC_FIEMAP returning 0 mapped extents for effectively empty files.map_file_extents
relies onnumber of mapped extent
s > 0 wihtout ever checking it, resulting in an integer underflow and subsequent segfault due to an out of bounds memory access.This commit fixes the issue by checking the number of mapped extents is not 0 before trying to access the last extent.
Signed-off-by: Tobias Schramm t.schramm@manjaro.org