Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/vfs/cpio/cpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,9 @@ cpio_create_entry (struct vfs_class *me, struct vfs_s_super *super, struct stat
// FIXME: do we must read from arch->fd in case of inode != NULL only or in any
// case?

inode->linkname = g_malloc (st->st_size + 1);
if (st->st_size < 0 || (gsize) st->st_size >= G_MAXSIZE)
Copy link
Copy Markdown
Contributor

@mc-worker mc-worker Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you reduce off_t to gsize? I think, sizeof (off_t) >= sizeof (gsize), so the correct way is

st->st_size >= (off_t) G_MAXSIZE

return STATUS_FAIL;
inode->linkname = g_malloc ((gsize) st->st_size + 1);

if (mc_read (arch->fd, inode->linkname, st->st_size) < st->st_size)
{
Expand Down Expand Up @@ -597,7 +599,12 @@ cpio_read_bin_head (struct vfs_class *me, struct vfs_s_super *super)
st.st_rdev = u.buf.c_rdev;
#endif
st.st_size = ((off_t) u.buf.c_filesizes[0] << 16) | u.buf.c_filesizes[1];

if (st.st_size < 0 || st.st_size > MC_MAXPATHLEN)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you compare file size with path length? It is correct for link not for regular file,

{
message (D_ERROR, MSG_ERROR, _ ("Corrupted cpio header encountered in\n%s"), super->name);
g_free (name);
return STATUS_FAIL;
}
vfs_zero_stat_times (&st);

st.st_atime = st.st_mtime = st.st_ctime =
Expand Down Expand Up @@ -751,7 +758,12 @@ cpio_read_crc_head (struct vfs_class *me, struct vfs_s_super *super)
u.st.st_rdev = makedev (hd.c_rdev, hd.c_rdevmin);
#endif
u.st.st_size = hd.c_filesize;

if (u.st.st_size < 0 || u.st.st_size > MC_MAXPATHLEN)
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise.

message (D_ERROR, MSG_ERROR, _ ("Corrupted cpio header encountered in\n%s"), super->name);
g_free (name);
return STATUS_FAIL;
}
vfs_zero_stat_times (&u.st);
u.st.st_atime = u.st.st_mtime = u.st.st_ctime = hd.c_mtime;

Expand Down
Loading