Skip to content

Commit e74345a

Browse files
committed
fix: update TSRMLS cache in APCu serializer callbacks on ZTS
The APCu (un)serializer callbacks are invoked from APCu's translation unit, where brotli's per-module _tsrm_ls_cache is not refreshed for the current thread. On ZTS shared builds this left the cache stale, so PHP_VAR_SERIALIZE_INIT dereferenced a bad pointer when accessing basic globals via BG(), crashing with SIGSEGV. NTS passed because it has no TSRMLS cache and BG() resolves directly. Refresh the cache with ZEND_TSRMLS_CACHE_UPDATE() at the entry of both callbacks, mirroring php_brotli_output_encoding().
1 parent 02970c6 commit e74345a

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

brotli.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,9 @@ static ZEND_FUNCTION(brotli_uncompress_add)
18431843
#if defined(HAVE_APCU_SUPPORT)
18441844
static int APC_SERIALIZER_NAME(brotli)(APC_SERIALIZER_ARGS)
18451845
{
1846+
#if defined(COMPILE_DL_BROTLI) && defined(ZTS)
1847+
ZEND_TSRMLS_CACHE_UPDATE();
1848+
#endif
18461849
int result;
18471850
int lgwin = BROTLI_DEFAULT_WINDOW;
18481851
long level = BROTLI_G(apcu_compression_level);
@@ -1883,6 +1886,9 @@ static int APC_SERIALIZER_NAME(brotli)(APC_SERIALIZER_ARGS)
18831886

18841887
static int APC_UNSERIALIZER_NAME(brotli)(APC_UNSERIALIZER_ARGS)
18851888
{
1889+
#if defined(COMPILE_DL_BROTLI) && defined(ZTS)
1890+
ZEND_TSRMLS_CACHE_UPDATE();
1891+
#endif
18861892
const uint8_t *next_in = (const uint8_t*) buf;
18871893
const unsigned char* tmp;
18881894
int result;

0 commit comments

Comments
 (0)