Bug #72801 [NEW]: apcu crashes (SIGSEGV) php/Apache on memory allocation failures

From: Date: Wed, 10 Aug 2016 11:28:06 +0000
Subject: Bug #72801 [NEW]: apcu crashes (SIGSEGV) php/Apache on memory allocation failures
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203144@lists.php.net to get a copy of this message
From:             jaromird at microsoft dot com
Operating system: Mac OS X
PHP version:      7.0.9
Package:          Reproducible crash
Bug Type:         Bug
Bug description:apcu crashes (SIGSEGV) php/Apache on memory allocation failures

Description:
------------
Started seeing more frequent Apache crashes after upgrade to PHP 7.0 for
one of our applications which makes heavy use of apc cache. After
investigation, found a reproduction script to trigger segmentation fault
eventually.

Late apcu code inspection revealed that code doesn't check for memory
allocation failures on many places. Typical case for example: string
duplication fails in apcu_store(), code then inserts zval with NULL
value into cache, then apcu_fetch() crashes when dereferencing the
value.

I hope I've covered all necessary places in the patch, but surely would
suggest close review. So far only the case triggered by the below test
is really tested.

Test script:
---------------
<?php

/*
Might need tweaking to trigger the memory allocation failure

ini settings:
memory_limit = 4512M
apcu shared memory size default - 128M
*/

$f = str_repeat('c', 800 * 1024 * 1024 );

apcu_store('aaa', $f, 5);

$s = apcu_fetch('aaa');

echo ($s == $f) ? "same" : "different";


Expected result:
----------------
script running to completion, returning "same" if no memory problem,
"different" if memory allocation failure in apc_fetch()

Actual result:
--------------
Segmentation fault: 11


-- 
Edit bug report at https://bugs.php.net/bug.php?id=72801&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=72801&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=72801&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=72801&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=72801&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=72801&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=72801&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=72801&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=72801&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=72801&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=72801&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=72801&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=72801&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=72801&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72801&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=72801&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=72801&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=72801&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72801&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=72801&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=72801&r=mysqlcfg



Thread (7 messages)

« previous php.bugs (#203144) next »