From: Scott MacVicar Date: Mon, 20 Oct 2008 23:35:47 +0000 (+0000) Subject: Fix bug #46331 - The internal magic db is const memory and segfaults when you try... X-Git-Tag: BEFORE_HEAD_NS_CHANGE~190 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=df2b71d2ca852291b0d72d7998659ef9f1721f1c;p=php Fix bug #46331 - The internal magic db is const memory and segfaults when you try to do byte swapping on big endian machines. This fixes it by copying the memory for those processors, but this isn't ideal as it wastes memory. Perhaps using a static cache would be better. --- diff --git a/ext/fileinfo/libmagic/apprentice.c b/ext/fileinfo/libmagic/apprentice.c index 211972ae24..563d82b19b 100644 --- a/ext/fileinfo/libmagic/apprentice.c +++ b/ext/fileinfo/libmagic/apprentice.c @@ -1913,6 +1913,16 @@ internal_loaded: goto error1; } + /* php_magic_database is a const, performing writes will segfault. This is for big-endian + machines only, PPC and Sparc specifically. Consider static variable or MINIT in + future. */ + if (needsbyteswap && fn == NULL) { + mm = emalloc(sizeof(php_magic_database)); + mm = memcpy(mm, php_magic_database, sizeof(php_magic_database)); + *magicp = mm; + ret = 1; + } + if (fn == NULL) { *nmagicp = (sizeof(php_magic_database) / sizeof(struct magic)); } else {