Tar entries with empty filenames are unusual but shouldn’t
cause a crash.  Handle this by following `tar` behavior:
substitute `.` for the empty filenames.

Fixes: 95d315fd7958 ("erofs-utils: introduce tarerofs")
Signed-off-by: Gao Xiang <hsiang...@linux.alibaba.com>
---
 lib/tar.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/tar.c b/lib/tar.c
index 2ea3858..0f21a60 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -826,8 +826,13 @@ 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)) {
+                       path[0] = '.';
+                       path[1] = '\0';
+               } else {
+                       while (path[j - 1] == '/')
+                               path[--j] = '\0';
+               }
        }
 
        dataoff = tar->offset;
-- 
2.43.5

Reply via email to