From: Gao Xiang Date: Fri, 28 Feb 2025 04:54:26 +0000 (+0800) Subject: erofs-utils: tar: handle empty filenames correctly X-Git-Tag: accepted/tizen/unified/20250610.081809~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ffa517605bf978cd76a4449143b1aad8b534d901;p=platform%2Fupstream%2Ferofs-utils.git erofs-utils: tar: handle empty filenames correctly Tar entries with empty filenames are unusual but shouldn't cause a crash. Handle this by following `tar` behavior: substitute `.` for the empty filenames. Reproducible image (base64-encoded gzipped blob): H4sICL2XwGcAA3Rlc3RfcmVhZF9mb3JtYXRfdGFyX2VtcHR5X2ZpbGVuYW1lLnRhcgBjY KA9MDAwMDc3VQDShuamBiAaBGA0hGNoaGBgZGJsaAZUaADiGDIomNLBbQylxSWJRUCnlG Tm4lVXnpGamoNHHtVTClR14ygYBaNgFNAAAAAE6urMAAYAAA== Fixes: 95d315fd7958 ("erofs-utils: introduce tarerofs") Signed-off-by: Gao Xiang Link: https://lore.kernel.org/r/20250228045426.81099-1-hsiangkao@linux.alibaba.com --- diff --git a/lib/tar.c b/lib/tar.c index 2ea3858..941fad2 100644 --- a/lib/tar.c +++ b/lib/tar.c @@ -826,8 +826,14 @@ out_eot: memcpy(path + j, th->name, sizeof(th->name)); path[j + sizeof(th->name)] = '\0'; j = strlen(path); - while (path[j - 1] == '/') - path[--j] = '\0'; + if (__erofs_unlikely(!j)) { + erofs_info("substituting '.' for empty filename"); + path[0] = '.'; + path[1] = '\0'; + } else { + while (path[j - 1] == '/') + path[--j] = '\0'; + } } dataoff = tar->offset;