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