|
|
b74969 |
Upstream test patch dropped (binary patch not supported)
|
|
|
b74969 |
|
|
|
b74969 |
|
|
|
b74969 |
From ede59c8feb4b80e1b94e4abdaa0711051e2912ab Mon Sep 17 00:00:00 2001
|
|
|
b74969 |
From: Anatol Belski <ab@php.net>
|
|
|
b74969 |
Date: Sun, 4 Jan 2015 14:20:21 +0100
|
|
|
b74969 |
Subject: [PATCH] Fixed bug #68735 fileinfo out-of-bounds memory access
|
|
|
b74969 |
|
|
|
b74969 |
---
|
|
|
b74969 |
NEWS | 7 +++++++
|
|
|
b74969 |
ext/fileinfo/libmagic/softmagic.c | 7 +++++--
|
|
|
b74969 |
ext/fileinfo/tests/bug68735.jpg | Bin 0 -> 24 bytes
|
|
|
b74969 |
ext/fileinfo/tests/bug68735.phpt | 16 ++++++++++++++++
|
|
|
b74969 |
4 files changed, 28 insertions(+), 2 deletions(-)
|
|
|
b74969 |
create mode 100644 ext/fileinfo/tests/bug68735.jpg
|
|
|
b74969 |
create mode 100644 ext/fileinfo/tests/bug68735.phpt
|
|
|
b74969 |
|
|
|
b74969 |
diff --git a/ext/fileinfo/libmagic/softmagic.c b/ext/fileinfo/libmagic/softmagic.c
|
|
|
b74969 |
index 7e0c856..e7b7855 100644
|
|
|
b74969 |
--- a/ext/fileinfo/libmagic/softmagic.c
|
|
|
b74969 |
+++ b/ext/fileinfo/libmagic/softmagic.c
|
|
|
b74969 |
@@ -884,14 +884,17 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
|
|
|
b74969 |
size_t sz = file_pstring_length_size(m);
|
|
|
b74969 |
char *ptr1 = p->s, *ptr2 = ptr1 + sz;
|
|
|
b74969 |
size_t len = file_pstring_get_length(m, ptr1);
|
|
|
b74969 |
- if (len >= sizeof(p->s)) {
|
|
|
b74969 |
+ sz = sizeof(p->s) - sz; /* maximum length of string */
|
|
|
b74969 |
+ if (len >= sz) {
|
|
|
b74969 |
/*
|
|
|
b74969 |
* The size of the pascal string length (sz)
|
|
|
b74969 |
* is 1, 2, or 4. We need at least 1 byte for NUL
|
|
|
b74969 |
* termination, but we've already truncated the
|
|
|
b74969 |
* string by p->s, so we need to deduct sz.
|
|
|
b74969 |
+ * Because we can use one of the bytes of the length
|
|
|
b74969 |
+ * after we shifted as NUL termination.
|
|
|
b74969 |
*/
|
|
|
b74969 |
- len = sizeof(p->s) - sz;
|
|
|
b74969 |
+ len = sz;
|
|
|
b74969 |
}
|
|
|
b74969 |
while (len--)
|
|
|
b74969 |
*ptr1++ = *ptr2++;
|