[php-src] PR #21472: RFC: Rename visible libmagic symbols
| From: | orlitzky | Date: | Fri, 20 Mar 2026 02:41:39 +0000 |
| Subject: | [php-src] PR #21472: RFC: Rename visible libmagic symbols | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-35273@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/21472
Author: orlitzky
Trying my hand at a very old problem ([PHP bug 66095](https://bugs.php.net/bug.php?id=66095),
[Gentoo bug 471682](https://bugs.gentoo.org/471682), [FreeBSD bug
195562](https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=195562))
The bundled libmagic for the fileinfo extension has some visible symbols:
```
$ objdump -TC /usr/lib/php8.5/apache2/libphp8.so | grep '\smagic_'
00000000002b3f34 g DF .text 0000000000000034 Base magic_compile
00000000002b3dde g DF .text 0000000000000024 Base magic_open
00000000002b3fd0 g DF .text 0000000000000034 Base magic_descriptor
00000000002b3f00 g DF .text 0000000000000034 Base magic_load
00000000002b43fa g DF .text 0000000000000032 Base magic_setflags
00000000002b3f9c g DF .text 0000000000000034 Base magic_list
00000000002b4442 g DF .text 0000000000000206 Base magic_setparam
00000000002b43d4 g DF .text 0000000000000026 Base magic_getflags
00000000002b439e g DF .text 0000000000000036 Base magic_errno
00000000002b4648 g DF .text 00000000000001f4 Base magic_getparam
00000000002b42f4 g DF .text 000000000000006e Base magic_buffer
00000000002b4362 g DF .text 000000000000003c Base magic_error
00000000002b3f68 g DF .text 0000000000000034 Base magic_check
00000000002b442c g DF .text 0000000000000016 Base magic_version
00000000002b3eda g DF .text 0000000000000026 Base magic_close
00000000002b4038 g DF .text 0000000000000034 Base magic_stream
00000000002b4004 g DF .text 0000000000000034 Base magic_file
```
This works fine until you load that shared library into a process that links against the system
libmagic, providing (in many cases, different versions of) the same symbols. I hit this myself
several years ago when using another apache module that linked against libmagic. I can't cite
any bug reports for the embed SAPI, but there is every reason to suspect that it suffers from the
same issue.
A fix was proposed on [PHP bug 66095](https://bugs.php.net/bug.php?id=66095), but given how few
problematic symbols there are, I think that it's easier to just rename them. I used find/sed
and then checked the diff -- it was actually quite short. We can see the new names (the embed SAPI,
in this case):
```
$ objdump -TC ./libs/libphp.so | grep php_magic
0000000000183aee g DF .text 0000000000000036 php_magic_errno
0000000000183a44 g DF .text 000000000000006e php_magic_buffer
0000000000183ab2 g DF .text 000000000000003c php_magic_error
00000000001836b8 g DF .text 0000000000000034 php_magic_check
0000000000183b7c g DF .text 0000000000000016 php_magic_version
000000000018362a g DF .text 0000000000000026 php_magic_close
0000000000183754 g DF .text 0000000000000034 php_magic_file
0000000000183684 g DF .text 0000000000000034 php_magic_compile
0000000000183788 g DF .text 0000000000000034 php_magic_stream
0000000000183b4a g DF .text 0000000000000032 php_magic_setflags
0000000000183720 g DF .text 0000000000000034 php_magic_descriptor
0000000000183b92 g DF .text 0000000000000206 php_magic_setparam
0000000000183b24 g DF .text 0000000000000026 php_magic_getflags
000000000018352e g DF .text 0000000000000024 php_magic_open
0000000000183d98 g DF .text 00000000000001f4 php_magic_getparam
0000000000183650 g DF .text 0000000000000034 php_magic_load
00000000001836ec g DF .text 0000000000000034 php_magic_list
```
The
strcasestr() commit is unrelated to an extent. I noticed (grep) that the only use
of strcasestr() in libmagic is patched out by PHP, so there is no need for it on any
platform. The -DHAVE_STRCASESTR=1 simply ensures that libmagic does not try to
prototype it.
It remains to construct a failing example, and check that the PR actually fixes it.