[packages/file] Rel 3. Backport upstream CDF parser and umask fixes from file git

arekm arekm at pld-linux.org
Thu Oct 29 08:33:25 CET 2026


commit 15a67f861e4df65db11d7532e6dbda33bf82e015
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Thu Oct 29 00:17:04 2026 +0100

    Rel 3. Backport upstream CDF parser and umask fixes from file git

 cdf-app-name-nul.patch | 33 ++++++++++++++++++++++++++
 cdf-catalog-loop.patch | 24 +++++++++++++++++++
 cdf-memory-limit.patch | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++
 file.spec              | 10 +++++++-
 pipe2file-umask.patch  | 33 ++++++++++++++++++++++++++
 5 files changed, 163 insertions(+), 1 deletion(-)
---
diff --git a/file.spec b/file.spec
index 863b7e9..ec1d9b7 100644
--- a/file.spec
+++ b/file.spec
@@ -35,7 +35,7 @@ Summary(zh_CN.UTF-8):	判定文件类型的工具。
 Summary(zh_TW.UTF-8):	用於決定檔案類型的一個工具程式。
 Name:		file
 Version:	5.48
-Release:	2
+Release:	3
 License:	distributable
 Group:		Applications/File
 Source0:	https://astron.com/pub/file/%{name}-%{version}.tar.gz
@@ -49,6 +49,10 @@ Patch0:		searchpath.patch
 Patch1:		automake.patch
 Patch2:		%{name}-gettext-no-random-translations.patch
 Patch3:		name-use-count.patch
+Patch4:		cdf-catalog-loop.patch
+Patch5:		cdf-app-name-nul.patch
+Patch6:		cdf-memory-limit.patch
+Patch7:		pipe2file-umask.patch
 URL:		http://www.darwinsys.com/file/
 BuildRequires:	autoconf >= 2.50
 BuildRequires:	automake
@@ -290,6 +294,10 @@ Wiązania Pythona 3 do biblioteki libmagic.
 %patch -P 1 -p1
 %patch -P 2 -p1
 %patch -P 3 -p1
+%patch -P 4 -p1
+%patch -P 5 -p1
+%patch -P 6 -p1
+%patch -P 7 -p1
 
 %if "%{_ver_lt '%{cc_version}' '3.4'}" == "1"
 %{__sed} -i -e 's,-Wextra,,' configure.ac
diff --git a/cdf-app-name-nul.patch b/cdf-app-name-nul.patch
new file mode 100644
index 0000000..4a237c8
--- /dev/null
+++ b/cdf-app-name-nul.patch
@@ -0,0 +1,33 @@
+From 029e5bae7362e71671b3e1f316d4f3936d8a7819 Mon Sep 17 00:00:00 2001
+From: Christos Zoulas <christos at zoulas.com>
+Date: Tue, 13 Oct 2026 15:54:12 +0000
+Subject: [PATCH] PR/812: mgl: NUL terminate string passed to cdf_app_to_mime()
+
+---
+ src/readcdf.c | 7 ++++---
+ 1 file changed, 4 insertions(+), 3 deletions(-)
+
+diff --git a/src/readcdf.c b/src/readcdf.c
+index ab2984d74..49f4f844b 100644
+--- a/src/readcdf.c
++++ b/src/readcdf.c
+@@ -397,7 +397,7 @@ cdf_check_summary_info(struct magic_set *ms, const cdf_info_t *info,
+ 	int i;
+ 	const char *str = NULL;
+ 	cdf_directory_t *d;
+-	char name[__arraycount(d->d_name)];
++	char name[__arraycount(d->d_name) + 1];
+ 	size_t j, k;
+ 
+ #ifdef CDF_DEBUG
+@@ -411,8 +411,9 @@ cdf_check_summary_info(struct magic_set *ms, const cdf_info_t *info,
+ 		return i;
+ 	for (j = 0; str == NULL && j < dir->dir_len; j++) {
+ 		d = &dir->dir_tab[j];
+-		for (k = 0; k < sizeof(name); k++)
++		for (k = 0; k < sizeof(name) - 1; k++)
+ 			name[k] = CAST(char, cdf_tole2(d->d_name[k]));
++		name[sizeof(name) - 1] = '\0';
+ 		str = cdf_app_to_mime(name,
+ 				      NOTMIME(ms) ? name2desc : name2mime);
+ 	}
diff --git a/cdf-catalog-loop.patch b/cdf-catalog-loop.patch
new file mode 100644
index 0000000..e478da2
--- /dev/null
+++ b/cdf-catalog-loop.patch
@@ -0,0 +1,24 @@
+From 4eae60a63cc185f97efb913f0a69cf064488e2a9 Mon Sep 17 00:00:00 2001
+From: Christos Zoulas <christos at zoulas.com>
+Date: Wed, 14 Oct 2026 16:54:08 +0000
+Subject: [PATCH] PR/181: soma0121: fix infinite loop in cdf_unpack_catalog on
+ zero-length record
+
+---
+ src/cdf.c | 5 ++++-
+ 1 file changed, 4 insertions(+), 1 deletion(-)
+
+diff --git a/src/cdf.c b/src/cdf.c
+index 27d4e6b74..ddf7bb546 100644
+--- a/src/cdf.c
++++ b/src/cdf.c
+@@ -1244,6 +1244,9 @@ cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst,
+ 		extract_catalog_field(uint64_t, ce_timestamp, 8);
+ 		reclen = cep->ce_namlen;
+ 
++		if (reclen == 0)
++			break;
++
+ 		if (reclen < 14) {
+ 			cep->ce_namlen = 0;
+ 			continue;
diff --git a/cdf-memory-limit.patch b/cdf-memory-limit.patch
new file mode 100644
index 0000000..6708674
--- /dev/null
+++ b/cdf-memory-limit.patch
@@ -0,0 +1,64 @@
+From 2220970c46420ef51e02b8ef39477d8ed868931e Mon Sep 17 00:00:00 2001
+From: Christos Zoulas <christos at zoulas.com>
+Date: Fri, 28 Aug 2026 15:45:34 +0000
+Subject: [PATCH] Limit memory use from the cdf parser (Acts1631)
+
+---
+ src/cdf.c | 22 ++++++++++++++++++----
+ src/cdf.h |  1 +
+ 2 files changed, 19 insertions(+), 4 deletions(-)
+
+diff --git a/src/cdf.c b/src/cdf.c
+index 2da240c1ca..9ebc9572ca 100644
+--- a/src/cdf.c
++++ b/src/cdf.c
+@@ -563,8 +564,12 @@ size_t
+ cdf_count_chain(const cdf_sat_t *sat, cdf_secid_t sid, size_t size)
+ {
+ 	size_t i, j;
+-	cdf_secid_t maxsector = CAST(cdf_secid_t, (sat->sat_len * size)
+-	    / sizeof(maxsector));
++	cdf_secid_t maxsector;
++
++	if (size == 0 || sat->sat_len > SIZE_MAX / size)
++		goto out;
++	maxsector = CAST(cdf_secid_t, (sat->sat_len * size) /
++	    sizeof(maxsector));
+ 
+ 	DPRINTF(("Chain:"));
+ 	if (sid == CDF_SECID_END_OF_CHAIN) {
+@@ -579,6 +584,10 @@ cdf_count_chain(const cdf_sat_t *sat, cdf_secid_t sid, size_t size)
+ 			DPRINTF(("Counting chain loop limit"));
+ 			goto out;
+ 		}
++		if (i >= CDF_MEMORY_LIMIT / size) {
++			DPRINTF(("Counting chain size limit"));
++			goto out;
++		}
+ 		if (sid >= maxsector) {
+ 			DPRINTF(("Sector %d >= %d\n", sid, maxsector));
+ 			goto out;
+@@ -715,6 +724,11 @@ cdf_read_dir(const cdf_info_t *info, const cdf_header_t *h,
+ 		return -1;
+ 
+ 	nd = ss / CDF_DIRECTORY_SIZE;
++	if (nd != 0 && ns > CDF_MEMORY_LIMIT / nd / sizeof(dir->dir_tab[0])) {
++		DPRINTF(("Directory size limit"));
++		errno = EFTYPE;
++		return -1;
++	}
+ 
+ 	dir->dir_len = ns * nd;
+ 	dir->dir_tab = CAST(cdf_directory_t *,
+diff --git a/src/cdf.h b/src/cdf.h
+index 6dddb3d65a..7f47555f09 100644
+--- a/src/cdf.h
++++ b/src/cdf.h
+@@ -49,6 +49,7 @@ typedef int32_t cdf_secid_t;
+ 
+ #define CDF_LOOP_LIMIT					10000
+ #define CDF_ELEMENT_LIMIT				100000
++#define CDF_MEMORY_LIMIT				(16 * 1024 * 1024)
+ 
+ #define CDF_SECID_NULL					0
+ #define CDF_SECID_FREE					-1
diff --git a/pipe2file-umask.patch b/pipe2file-umask.patch
new file mode 100644
index 0000000..6fea5c4
--- /dev/null
+++ b/pipe2file-umask.patch
@@ -0,0 +1,33 @@
+From f54b0776b92527be98033f8f73d09faf2d540188 Mon Sep 17 00:00:00 2001
+From: Christos Zoulas <christos at zoulas.com>
+Date: Thu, 22 Oct 2026 15:44:03 +0000
+Subject: [PATCH] PR/183:soma0121: file_pipe2file sets umask(0) around mkstemp
+ and restores it afterwards. umask is process-wide, so in a threaded libmagic
+ consumer any file another thread creates during that window gets no umask
+ applied: open(path, O_CREAT, 0666) under umask 022 comes out 0666. the window
+ opens whenever magic_descriptor is handed a pipe or socket whose data starts
+ with an ELF header (file_tryelf -> file_pipe2file), so whoever supplies that
+ stream can keep reopening it. with one thread identifying a 256-byte ELF
+ header from pipes and another creating files under umask 022, 33715 of 200000
+ files came out 0666; with umask(0177) it is 0 of 200000 and the tests still
+ pass. 0177 also keeps the temporary 0600 on libcs whose mkstemp honours the
+ umask. a file created concurrently can still pick up the temporary mask, but
+ that only makes it more restrictive, never group or world writable.
+
+---
+ src/compress.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/compress.c b/src/compress.c
+index 0296ec3d2..058760c97 100644
+--- a/src/compress.c
++++ b/src/compress.c
+@@ -544,7 +544,7 @@ file_pipe2file(struct magic_set *ms, int fd, const void *startbuf,
+ #else
+ 	{
+ 		int te;
+-		mode_t ou = umask(0);
++		mode_t ou = umask(0177);
+ 		tfd = mkstemp(buf);
+ 		(void)umask(ou);
+ 		te = errno;
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/file.git/commitdiff/15a67f861e4df65db11d7532e6dbda33bf82e015



More information about the pld-cvs-commit mailing list