diff options
Diffstat (limited to 'ext/fileinfo/libmagic.patch')
-rw-r--r-- | ext/fileinfo/libmagic.patch | 348 |
1 files changed, 13 insertions, 335 deletions
diff --git a/ext/fileinfo/libmagic.patch b/ext/fileinfo/libmagic.patch index 30f1e9b450..b8e43b602d 100644 --- a/ext/fileinfo/libmagic.patch +++ b/ext/fileinfo/libmagic.patch @@ -3038,341 +3038,6 @@ diff -u libmagic.orig/readcdf.c libmagic/readcdf.c } if (NOTMIME(ms)) { if (str != NULL) { -diff -u libmagic.orig/readelf.c libmagic/readelf.c ---- libmagic.orig/readelf.c Tue Nov 5 16:44:01 2013 -+++ libmagic/readelf.c Sat Oct 25 11:42:59 2014 -@@ -42,14 +42,14 @@ - #include "magic.h" - - #ifdef ELFCORE --private int dophn_core(struct magic_set *, int, int, int, off_t, int, size_t, -- off_t, int *); -+private int dophn_core(struct magic_set *, int, int, int, zend_off_t, int, size_t, -+ zend_off_t, int *); - #endif - private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t, -- off_t, int *, int); -+ zend_off_t, int *, int); - private int doshn(struct magic_set *, int, int, int, off_t, int, size_t, -- off_t, int *, int, int); --private size_t donote(struct magic_set *, void *, size_t, size_t, int, -+ zend_off_t, int *, int); -+private size_t donote(struct magic_set *, unsigned char *, size_t, size_t, int, - int, size_t, int *); - - #define ELF_ALIGN(a) ((((a) + align - 1) / align) * align) -@@ -127,7 +127,13 @@ - - #define elf_getu16(swap, value) getu16(swap, value) - #define elf_getu32(swap, value) getu32(swap, value) --#define elf_getu64(swap, value) getu64(swap, value) -+#ifdef USE_ARRAY_FOR_64BIT_TYPES -+# define elf_getu64(swap, array) \ -+ ((swap ? ((uint64_t)elf_getu32(swap, array[0])) << 32 : elf_getu32(swap, array[0])) + \ -+ (swap ? elf_getu32(swap, array[1]) : ((uint64_t)elf_getu32(swap, array[1]) << 32))) -+#else -+# define elf_getu64(swap, value) getu64(swap, value) -+#endif - - #define xsh_addr (clazz == ELFCLASS32 \ - ? (void *)&sh32 \ -@@ -138,7 +144,7 @@ - #define xsh_size (size_t)(clazz == ELFCLASS32 \ - ? elf_getu32(swap, sh32.sh_size) \ - : elf_getu64(swap, sh64.sh_size)) --#define xsh_offset (off_t)(clazz == ELFCLASS32 \ -+#define xsh_offset (zend_off_t)(clazz == ELFCLASS32 \ - ? elf_getu32(swap, sh32.sh_offset) \ - : elf_getu64(swap, sh64.sh_offset)) - #define xsh_type (clazz == ELFCLASS32 \ -@@ -156,13 +162,13 @@ - #define xph_type (clazz == ELFCLASS32 \ - ? elf_getu32(swap, ph32.p_type) \ - : elf_getu32(swap, ph64.p_type)) --#define xph_offset (off_t)(clazz == ELFCLASS32 \ -+#define xph_offset (zend_off_t)(clazz == ELFCLASS32 \ - ? elf_getu32(swap, ph32.p_offset) \ - : elf_getu64(swap, ph64.p_offset)) - #define xph_align (size_t)((clazz == ELFCLASS32 \ -- ? (off_t) (ph32.p_align ? \ -+ ? (zend_off_t) (ph32.p_align ? \ - elf_getu32(swap, ph32.p_align) : 4) \ -- : (off_t) (ph64.p_align ? \ -+ : (zend_off_t) (ph64.p_align ? \ - elf_getu64(swap, ph64.p_align) : 4))) - #define xph_filesz (size_t)((clazz == ELFCLASS32 \ - ? elf_getu32(swap, ph32.p_filesz) \ -@@ -287,12 +293,12 @@ - #define FLAGS_IS_CORE 0x10 - - private int --dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off, -- int num, size_t size, off_t fsize, int *flags) -+dophn_core(struct magic_set *ms, int clazz, int swap, int fd, zend_off_t off, -+ int num, size_t size, zend_off_t fsize, int *flags) - { - Elf32_Phdr ph32; - Elf64_Phdr ph64; -- size_t offset, len; -+ size_t offset; - unsigned char nbuf[BUFSIZ]; - ssize_t bufsize; - -@@ -306,7 +312,11 @@ - * Loop through all the program headers. - */ - for ( ; num; num--) { -- if (pread(fd, xph_addr, xph_sizeof, off) == -1) { -+ if (FINFO_LSEEK_FUNC(fd, off, SEEK_SET) == (zend_off_t)-1) { -+ file_badseek(ms); -+ return -1; -+ } -+ if (FINFO_READ_FUNC(fd, xph_addr, xph_sizeof) == -1) { - file_badread(ms); - return -1; - } -@@ -324,8 +334,13 @@ - * This is a PT_NOTE section; loop through all the notes - * in the section. - */ -- len = xph_filesz < sizeof(nbuf) ? xph_filesz : sizeof(nbuf); -- if ((bufsize = pread(fd, nbuf, len, xph_offset)) == -1) { -+ if (FINFO_LSEEK_FUNC(fd, xph_offset, SEEK_SET) == (zend_off_t)-1) { -+ file_badseek(ms); -+ return -1; -+ } -+ bufsize = FINFO_READ_FUNC(fd, nbuf, -+ ((xph_filesz < sizeof(nbuf)) ? xph_filesz : sizeof(nbuf))); -+ if (bufsize == -1) { - file_badread(ms); - return -1; - } -@@ -477,6 +492,13 @@ - uint32_t namesz, descsz; - unsigned char *nbuf = CAST(unsigned char *, vbuf); - -+ if (xnh_sizeof + offset > size) { -+ /* -+ * We're out of note headers. -+ */ -+ return xnh_sizeof + offset; -+ } -+ - (void)memcpy(xnh_addr, &nbuf[offset], xnh_sizeof); - offset += xnh_sizeof; - -@@ -902,7 +924,7 @@ - Elf64_Shdr sh64; - int stripped = 1; - void *nbuf; -- off_t noff, coff, name_off; -+ zend_off_t noff, coff, name_off; - uint64_t cap_hw1 = 0; /* SunOS 5.x hardware capabilites */ - uint64_t cap_sf1 = 0; /* SunOS 5.x software capabilites */ - char name[50]; -@@ -913,24 +935,12 @@ - return 0; - } - -- /* Read offset of name section to be able to read section names later */ -- if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) == -1) { -- file_badread(ms); -- return -1; -- } -- name_off = xsh_offset; -- - for ( ; num; num--) { -- /* Read the name of this section. */ -- if (pread(fd, name, sizeof(name), name_off + xsh_name) == -1) { -- file_badread(ms); -+ if (FINFO_LSEEK_FUNC(fd, off, SEEK_SET) == (zend_off_t)-1) { -+ file_badseek(ms); - return -1; - } -- name[sizeof(name) - 1] = '\0'; -- if (strcmp(name, ".debug_info") == 0) -- stripped = 0; -- -- if (pread(fd, xsh_addr, xsh_sizeof, off) == -1) { -+ if (FINFO_READ_FUNC(fd, xsh_addr, xsh_sizeof) == -1) { - file_badread(ms); - return -1; - } -@@ -955,41 +965,35 @@ - /* Things we can determine when we seek */ - switch (xsh_type) { - case SHT_NOTE: -- if ((nbuf = malloc(xsh_size)) == NULL) { -- file_error(ms, errno, "Cannot allocate memory" -- " for note"); -+ nbuf = emalloc((size_t)xsh_size); -+ if ((noff = FINFO_LSEEK_FUNC(fd, (zend_off_t)xsh_offset, SEEK_SET)) == -+ (zend_off_t)-1) { -+ file_badread(ms); -+ efree(nbuf); - return -1; - } -- if (pread(fd, nbuf, xsh_size, xsh_offset) == -1) { -+ if (FINFO_READ_FUNC(fd, nbuf, (size_t)xsh_size) != -+ (ssize_t)xsh_size) { - file_badread(ms); -- free(nbuf); -+ efree(nbuf); - return -1; - } - - noff = 0; - for (;;) { -- if (noff >= (off_t)xsh_size) -+ if (noff >= (zend_off_t)xsh_size) - break; - noff = donote(ms, nbuf, (size_t)noff, -- xsh_size, clazz, swap, 4, flags); -+ (size_t)xsh_size, clazz, swap, 4, -+ flags); - if (noff == 0) - break; - } -- free(nbuf); -+ efree(nbuf); - break; - case SHT_SUNW_cap: -- switch (mach) { -- case EM_SPARC: -- case EM_SPARCV9: -- case EM_IA_64: -- case EM_386: -- case EM_AMD64: -- break; -- default: -- goto skip; -- } -- -- if (lseek(fd, xsh_offset, SEEK_SET) == (off_t)-1) { -+ if (FINFO_LSEEK_FUNC(fd, (zend_off_t)xsh_offset, SEEK_SET) == -+ (zend_off_t)-1) { - file_badseek(ms); - return -1; - } -@@ -999,9 +1003,9 @@ - Elf64_Cap cap64; - char cbuf[/*CONSTCOND*/ - MAX(sizeof cap32, sizeof cap64)]; -- if ((coff += xcap_sizeof) > (off_t)xsh_size) -+ if ((coff += xcap_sizeof) > (zend_off_t)xsh_size) - break; -- if (read(fd, cbuf, (size_t)xcap_sizeof) != -+ if (FINFO_READ_FUNC(fd, cbuf, (size_t)xcap_sizeof) != - (ssize_t)xcap_sizeof) { - file_badread(ms); - return -1; -@@ -1027,13 +1031,12 @@ - break; - } - } -- /*FALLTHROUGH*/ -- skip: -+ break; -+ - default: - break; - } - } -- - if (file_printf(ms, ", %sstripped", stripped ? "" : "not ") == -1) - return -1; - if (cap_hw1) { -@@ -1103,8 +1106,8 @@ - * otherwise it's statically linked. - */ - private int --dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off, -- int num, size_t size, off_t fsize, int *flags, int sh_num) -+dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, zend_off_t off, -+ int num, size_t size, zend_off_t fsize, int *flags, int sh_num) - { - Elf32_Phdr ph32; - Elf64_Phdr ph64; -@@ -1112,7 +1115,7 @@ - const char *shared_libraries = ""; - unsigned char nbuf[BUFSIZ]; - ssize_t bufsize; -- size_t offset, align, len; -+ size_t offset, align; - - if (size != xph_sizeof) { - if (file_printf(ms, ", corrupted program header size") == -1) -@@ -1121,8 +1124,13 @@ - } - - for ( ; num; num--) { -- if (pread(fd, xph_addr, xph_sizeof, off) == -1) { -- file_badread(ms); -+ if (FINFO_LSEEK_FUNC(fd, off, SEEK_SET) == (zend_off_t)-1) { -+ file_badseek(ms); -+ return -1; -+ } -+ -+ if (FINFO_READ_FUNC(fd, xph_addr, xph_sizeof) == -1) { -+ file_badread(ms); - return -1; - } - -@@ -1160,9 +1168,12 @@ - * This is a PT_NOTE section; loop through all the notes - * in the section. - */ -- len = xph_filesz < sizeof(nbuf) ? xph_filesz -- : sizeof(nbuf); -- bufsize = pread(fd, nbuf, len, xph_offset); -+ if (FINFO_LSEEK_FUNC(fd, xph_offset, SEEK_SET) == (zend_off_t)-1) { -+ file_badseek(ms); -+ return -1; -+ } -+ bufsize = FINFO_READ_FUNC(fd, nbuf, ((xph_filesz < sizeof(nbuf)) ? -+ xph_filesz : sizeof(nbuf))); - if (bufsize == -1) { - file_badread(ms); - return -1; -@@ -1200,7 +1211,7 @@ - int clazz; - int swap; - struct stat st; -- off_t fsize; -+ zend_off_t fsize; - int flags = 0; - Elf32_Ehdr elf32hdr; - Elf64_Ehdr elf64hdr; -@@ -1223,7 +1234,7 @@ - /* - * If we cannot seek, it must be a pipe, socket or fifo. - */ -- if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE)) -+ if((FINFO_LSEEK_FUNC(fd, (zend_off_t)0, SEEK_SET) == (zend_off_t)-1) && (errno == ESPIPE)) - fd = file_pipe2file(ms, fd, buf, nbytes); - - if (fstat(fd, &st) == -1) { -diff -u libmagic.orig/readelf.h libmagic/readelf.h ---- libmagic.orig/readelf.h Tue Nov 5 16:41:56 2013 -+++ libmagic/readelf.h Wed Aug 27 12:35:45 2014 -@@ -44,9 +44,17 @@ - typedef uint32_t Elf32_Word; - typedef uint8_t Elf32_Char; - -+#if SIZEOF_LONG_LONG != 8 -+#define USE_ARRAY_FOR_64BIT_TYPES -+typedef uint32_t Elf64_Addr[2]; -+typedef uint32_t Elf64_Off[2]; -+typedef uint32_t Elf64_Xword[2]; -+#else -+#undef USE_ARRAY_FOR_64BIT_TYPES - typedef uint64_t Elf64_Addr; - typedef uint64_t Elf64_Off; - typedef uint64_t Elf64_Xword; -+#endif - typedef uint16_t Elf64_Half; - typedef uint32_t Elf64_Word; - typedef uint8_t Elf64_Char; diff -u libmagic.orig/softmagic.c libmagic/softmagic.c --- libmagic.orig/softmagic.c Thu Feb 13 00:20:53 2014 +++ libmagic/softmagic.c Fri Sep 19 16:29:55 2014 @@ -3879,3 +3544,16 @@ diff -u libmagic.orig/strcasestr.c libmagic/strcasestr.c #include <assert.h> #include <ctype.h> #include <string.h> +diff --git libmagic/file.h libmagic/file.h +index 0a5c19c..2b2405f 100644 +--- libmagic/file.h ++++ libmagic/file.h +@@ -419,8 +419,6 @@ protected int file_pipe2file(struct magic_set *, int, const void *, size_t); + protected int file_replace(struct magic_set *, const char *, const char *); + protected int file_printf(struct magic_set *, const char *, ...); + protected int file_reset(struct magic_set *); +-protected int file_tryelf(struct magic_set *, int, const unsigned char *, +- size_t); + protected int file_trycdf(struct magic_set *, int, const unsigned char *, + size_t); + #ifdef PHP_FILEINFO_UNCOMPRESS |