@@ -227,8 +227,17 @@ static void *zend_file_cache_unserialize_interned(zend_string *str, int in_shm)
227
227
if (in_shm ) {
228
228
ret = accel_new_interned_string (str );
229
229
if (ret == str ) {
230
+ /* We have to create new SHM allocated string */
231
+ size_t size = _ZSTR_STRUCT_SIZE (ZSTR_LEN (str ));
232
+ ret = zend_shared_alloc (size );
233
+ if (!ret ) {
234
+ zend_accel_schedule_restart_if_necessary (ACCEL_RESTART_OOM );
235
+ LONGJMP (* EG (bailout ), FAILURE );
236
+ }
237
+ memcpy (ret , str , size );
230
238
/* String wasn't interned but we will use it as interned anyway */
231
- GC_FLAGS (ret ) |= IS_STR_INTERNED | IS_STR_PERMANENT ;
239
+ GC_REFCOUNT (ret ) = 1 ;
240
+ GC_TYPE_INFO (ret ) = IS_STRING | ((IS_STR_INTERNED | IS_STR_PERSISTENT | IS_STR_PERMANENT ) << 8 );
232
241
}
233
242
} else {
234
243
ret = str ;
@@ -1303,6 +1312,7 @@ zend_persistent_script *zend_file_cache_script_load(zend_file_handle *file_handl
1303
1312
zend_accel_hash_entry * bucket ;
1304
1313
void * mem , * checkpoint , * buf ;
1305
1314
int cache_it = 1 ;
1315
+ int ok ;
1306
1316
1307
1317
if (!full_path ) {
1308
1318
return NULL ;
@@ -1395,6 +1405,7 @@ zend_persistent_script *zend_file_cache_script_load(zend_file_handle *file_handl
1395
1405
1396
1406
if (!ZCG (accel_directives ).file_cache_only &&
1397
1407
!ZCSG (restart_in_progress ) &&
1408
+ !ZSMMG (memory_exhausted ) &&
1398
1409
accelerator_shm_read_lock () == SUCCESS ) {
1399
1410
/* exclusive lock */
1400
1411
zend_shared_alloc_lock ();
@@ -1444,7 +1455,24 @@ zend_persistent_script *zend_file_cache_script_load(zend_file_handle *file_handl
1444
1455
ZCG (mem ) = ((char * )mem + info .mem_size );
1445
1456
script = (zend_persistent_script * )((char * )buf + info .script_offset );
1446
1457
script -> corrupted = !cache_it ; /* used to check if script restored to SHM or process memory */
1447
- zend_file_cache_unserialize (script , buf );
1458
+
1459
+ ok = 1 ;
1460
+ zend_try {
1461
+ zend_file_cache_unserialize (script , buf );
1462
+ } zend_catch {
1463
+ ok = 0 ;
1464
+ } zend_end_try ();
1465
+ if (!ok ) {
1466
+ if (cache_it ) {
1467
+ zend_shared_alloc_unlock ();
1468
+ goto use_process_mem ;
1469
+ } else {
1470
+ zend_arena_release (& CG (arena ), checkpoint );
1471
+ efree (filename );
1472
+ return NULL ;
1473
+ }
1474
+ }
1475
+
1448
1476
script -> corrupted = 0 ;
1449
1477
1450
1478
if (cache_it ) {
0 commit comments