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