cvs: php-src /ext/fileinfo/libmagic apprentice.c
| From: | Scott MacVicar | Date: | Mon, 20 Oct 2008 23:35:47 +0000 |
| Subject: | cvs: php-src /ext/fileinfo/libmagic apprentice.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-53620@lists.php.net to get a copy of this message | ||
scottmac Mon Oct 20 23:35:47 2008 UTC
Modified files:
/php-src/ext/fileinfo/libmagic apprentice.c
Log:
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.
http://cvs.php.net/viewvc.cgi/php-src/ext/fileinfo/libmagic/apprentice.c?r1=1.13&r2=1.14&diff_format=u
Index: php-src/ext/fileinfo/libmagic/apprentice.c
diff -u php-src/ext/fileinfo/libmagic/apprentice.c:1.13
php-src/ext/fileinfo/libmagic/apprentice.c:1.14
--- php-src/ext/fileinfo/libmagic/apprentice.c:1.13 Wed Oct 15 22:57:22 2008
+++ php-src/ext/fileinfo/libmagic/apprentice.c Mon Oct 20 23:35:47 2008
@@ -1913,6 +1913,16 @@
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 {