pengutronix / genimage

tool to generate multiple filesystem and flash images from a tree
GNU General Public License v2.0
308 stars 110 forks source link

util: fix segfault in map_file_extents for effectively zero size files #106

Closed TobleMiner closed 4 years ago

TobleMiner commented 4 years ago

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.

Signed-off-by: Tobias Schramm t.schramm@manjaro.org

michaelolbrich commented 4 years ago

Looks good. Thanks.