From 85c4c9225cebcf8e8c82e26f3a3d203089628134 Mon Sep 17 00:00:00 2001 From: David Wronek Date: Wed, 28 Jan 2026 10:51:08 +0100 Subject: [PATCH] sebaubuntu_libs: libcompat: distutils: do not copy character devices Ramdisks can contain character device inside the cpio archive, which can cause issues when running dumpyara as root, since cpio will extract character devices as well when it has elevated permissions. Signed-off-by: David Wronek --- .../libcompat/distutils/file_util.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/sebaubuntu_libs/libcompat/distutils/file_util.py b/sebaubuntu_libs/libcompat/distutils/file_util.py index a5080a3..b53c1d7 100644 --- a/sebaubuntu_libs/libcompat/distutils/file_util.py +++ b/sebaubuntu_libs/libcompat/distutils/file_util.py @@ -103,12 +103,19 @@ def copy_file( # noqa: C901 # (not update) and (src newer than dst). from ._modified import newer - from stat import S_IMODE, ST_ATIME, ST_MODE, ST_MTIME + from stat import S_IMODE, S_ISCHR, ST_ATIME, ST_MODE, ST_MTIME + + st = os.stat(src) if not os.path.isfile(src): - raise DistutilsFileError( - "can't copy '%s': doesn't exist or not a regular file" % src - ) + if S_ISCHR(st[ST_MODE]): + if verbose >= 1: + LOGD("not copying %s (file is character device)", src) + return (dst, 0) + else: + raise DistutilsFileError( + "can't copy '%s': doesn't exist or not a regular file" % src + ) if os.path.isdir(dst): dir = dst @@ -156,8 +163,6 @@ def copy_file( # noqa: C901 # (optionally) copy the times and mode. _copy_file_contents(src, dst) if preserve_mode or preserve_times: - st = os.stat(src) - # According to David Ascher , utime() should be done # before chmod() (at least under NT). if preserve_times: