d2399a
From 22736b7c56d678f142d5dd21f4996e5819507a2b Mon Sep 17 00:00:00 2001
d2399a
From: Stanislav Malyshev <stas@php.net>
d2399a
Date: Mon, 26 May 2014 17:42:18 -0700
d2399a
Subject: [PATCH] Fix bug #67327: fileinfo: CDF infinite loop in nelements DoS
d2399a
d2399a
Upstream fix: https://github.com/file/file/commit/f97486ef5dc3e8735440edc4fc8808c63e1a3ef0
d2399a
---
d2399a
 ext/fileinfo/libmagic/cdf.c | 8 +++++++-
d2399a
 1 file changed, 7 insertions(+), 1 deletion(-)
d2399a
d2399a
diff --git a/ext/fileinfo/libmagic/cdf.c b/ext/fileinfo/libmagic/cdf.c
d2399a
index 8dacd2f..4712e84 100644
d2399a
--- a/ext/fileinfo/libmagic/cdf.c
d2399a
+++ b/ext/fileinfo/libmagic/cdf.c
d2399a
@@ -823,6 +823,10 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
d2399a
 		    i, inp[i].pi_id, inp[i].pi_type, q - p, offs));
d2399a
 		if (inp[i].pi_type & CDF_VECTOR) {
d2399a
 			nelements = CDF_GETUINT32(q, 1);
d2399a
+			if (nelements == 0) {
d2399a
+				DPRINTF(("CDF_VECTOR with nelements == 0\n"));
d2399a
+				goto out;
d2399a
+			}
d2399a
 			o = 2;
d2399a
 		} else {
d2399a
 			nelements = 1;
d2399a
@@ -897,7 +901,9 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
d2399a
 			}
d2399a
 			DPRINTF(("nelements = %" SIZE_T_FORMAT "u\n",
d2399a
 			    nelements));
d2399a
-			for (j = 0; j < nelements; j++, i++) {
d2399a
+			for (j = 0; j < nelements && i < sh.sh_properties; 
d2399a
+			    j++, i++) 
d2399a
+			{
d2399a
 				uint32_t l = CDF_GETUINT32(q, o);
d2399a
 				inp[i].pi_str.s_len = l;
d2399a
 				inp[i].pi_str.s_buf = (const char *)
d2399a
-- 
d2399a
1.9.2
d2399a