Skip to content

Commit 4698200

Browse files
committed
Fix libmagic buffer overflow issue (CVE-2019-18218)
Ported from file/file@46a8443
1 parent 52f0498 commit 4698200

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

ext/fileinfo/libmagic/cdf.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,9 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
872872
i, inp[i].pi_id, inp[i].pi_type, q - p, offs));
873873
if (inp[i].pi_type & CDF_VECTOR) {
874874
nelements = CDF_GETUINT32(q, 1);
875-
if (nelements == 0) {
876-
DPRINTF(("CDF_VECTOR with nelements == 0\n"));
875+
if (nelements > CDF_ELEMENT_LIMIT || nelements == 0) {
876+
DPRINTF(("CDF_VECTOR with nelements == %"
877+
SIZE_T_FORMAT "u\n", nelements));
877878
goto out;
878879
}
879880
o = 2;
@@ -948,8 +949,6 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
948949
*info = inp;
949950
inp = *info + nelem;
950951
}
951-
DPRINTF(("nelements = %" SIZE_T_FORMAT "u\n",
952-
nelements));
953952
for (j = 0; j < nelements && i < sh.sh_properties;
954953
j++, i++)
955954
{

ext/fileinfo/libmagic/cdf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
typedef int32_t cdf_secid_t;
5151

5252
#define CDF_LOOP_LIMIT 10000
53+
#define CDF_ELEMENT_LIMIT 100000
5354

5455
#define CDF_SECID_NULL 0
5556
#define CDF_SECID_FREE -1

0 commit comments

Comments
 (0)