diff options
author | Remi Collet <remi@php.net> | 2014-06-10 14:02:36 +0200 |
---|---|---|
committer | Stanislav Malyshev <stas@php.net> | 2014-07-18 16:17:36 -0700 |
commit | 6bd5a06894fa2f8c1b53bf92fb809d911b740e84 (patch) | |
tree | fdc18ad6f6c71b5b56529e7e58e31f2a1d4c2189 | |
parent | ec002bd837bec0c6032b58ff2b7216a9ecf45793 (diff) | |
download | php-git-6bd5a06894fa2f8c1b53bf92fb809d911b740e84.tar.gz |
Fixed Bug #67410 fileinfo: mconvert incorrect handling of truncated pascal string size
Upstream
https://github.com/file/file/commit/27a14bc7ba285a0a5ebfdb55e54001aa11932b08
-rw-r--r-- | ext/fileinfo/libmagic/softmagic.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/ext/fileinfo/libmagic/softmagic.c b/ext/fileinfo/libmagic/softmagic.c index f9c2836dd2..e598981839 100644 --- a/ext/fileinfo/libmagic/softmagic.c +++ b/ext/fileinfo/libmagic/softmagic.c @@ -777,10 +777,18 @@ mconvert(struct magic_set *ms, struct magic *m) 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'; |