com php-src: Fixed Bug #67410 fileinfo: mconvert incorrect handling of truncated pascal string size: ext/fileinfo/libmagic/softmagic.c
| From: | Remi Collet | Date: | Tue, 10 Jun 2014 12:02:36 +0000 |
| Subject: | com php-src: Fixed Bug #67410 fileinfo: mconvert incorrect handling of truncated pascal string size: ext/fileinfo/libmagic/softmagic.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-78796@lists.php.net to get a copy of this message | ||
Commit: e77659a8c87272e5061738a31430d2111482c426
Author: Remi Collet <remi@php.net> Tue, 10 Jun 2014 14:02:36 +0200
Parents: 949cab09f24abb80b8585af744bd964dc17f7401
Branches: PHP-5.4 PHP-5.5 PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e77659a8c87272e5061738a31430d2111482c426
Log:
Fixed Bug #67410 fileinfo: mconvert incorrect handling of truncated pascal string size
Upstream
https://github.com/file/file/commit/27a14bc7ba285a0a5ebfdb55e54001aa11932b08
Bugs:
https://bugs.php.net/67410
Changed paths:
M ext/fileinfo/libmagic/softmagic.c
Diff:
diff --git a/ext/fileinfo/libmagic/softmagic.c b/ext/fileinfo/libmagic/softmagic.c
index 21fea6b..01e4977 100644
--- a/ext/fileinfo/libmagic/softmagic.c
+++ b/ext/fileinfo/libmagic/softmagic.c
@@ -881,10 +881,18 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
return 1;
}
case FILE_PSTRING: {
- char *ptr1 = p->s, *ptr2 = ptr1 + file_pstring_length_size(m);
+ size_t sz = file_pstring_length_size(m);
+ char *ptr1 = p->s, *ptr2 = ptr1 + sz;
size_t len = file_pstring_get_length(m, ptr1);
- if (len >= sizeof(p->s))
- len = sizeof(p->s) - 1;
+ if (len >= sizeof(p->s)) {
+ /*
+ * The size of the pascal string length (sz)
+ * is 1, 2, or 4. We need at least 1 byte for NUL
+ * termination, but we've already truncated the
+ * string by p->s, so we need to deduct sz.
+ */
+ len = sizeof(p->s) - sz;
+ }
while (len--)
*ptr1++ = *ptr2++;
*ptr1 = '\0';