From 51928ebca4576cefb87901c133923d5185cc13ff Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Fri, 10 Jul 2026 11:58:28 -0400 Subject: [PATCH] cpio: correctly detect end of archive Signed-off-by: Michael Shaw --- fs/vfs/initcpio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/vfs/initcpio.c b/fs/vfs/initcpio.c index 2b689ca..6444f80 100644 --- a/fs/vfs/initcpio.c +++ b/fs/vfs/initcpio.c @@ -53,7 +53,7 @@ static ssize_t read_next(fs_t *fs, const char *file, rbtree_t *list, dirent_t ** return -ENAMETOOLONG; const char *cursor = file + sizeof(struct cpio_newc_header); - size_t data_offset = sizeof(struct cpio_newc_header) + ALIGN_UP(name_len, 4); + size_t data_offset = ALIGN_UP(sizeof(struct cpio_newc_header) + name_len, 4); if (!strncmp(cursor, "./", 2)) { cursor += 2; @@ -66,6 +66,10 @@ static ssize_t read_next(fs_t *fs, const char *file, rbtree_t *list, dirent_t ** memcpy(name, cursor, name_len); cursor = file + data_offset; + if(file_len == 0 && !strcmp(name, CPIO_TRAILER)) { + return 0; + } + char *parent_path = dirname(name); char *leaf = basename(name);