Skip to content

Commit 75baa72

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #79917
2 parents 9e93090 + 4609ded commit 75baa72

File tree

1 file changed

+46
-34
lines changed

1 file changed

+46
-34
lines changed

ext/opcache/zend_file_cache.c

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,13 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
449449
zend_file_cache_metainfo *info,
450450
void *buf)
451451
{
452-
if (op_array->static_variables && !IS_SERIALIZED(op_array->static_variables)) {
452+
/* Check whether this op_array has already been serialized. */
453+
if (IS_SERIALIZED(op_array->opcodes)) {
454+
ZEND_ASSERT(op_array->scope && "Only method op_arrays should be shared");
455+
return;
456+
}
457+
458+
if (op_array->static_variables) {
453459
HashTable *ht;
454460

455461
SERIALIZE_PTR(op_array->static_variables);
@@ -458,7 +464,14 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
458464
zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval);
459465
}
460466

461-
if (op_array->scope && !IS_SERIALIZED(op_array->opcodes)) {
467+
ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, &op_array->static_variables);
468+
if (op_array->fn_flags & ZEND_ACC_IMMUTABLE) {
469+
ZEND_MAP_PTR_INIT(op_array->run_time_cache, NULL);
470+
} else {
471+
SERIALIZE_PTR(ZEND_MAP_PTR(op_array->run_time_cache));
472+
}
473+
474+
if (op_array->scope) {
462475
if (UNEXPECTED(zend_shared_alloc_get_xlat_entry(op_array->opcodes))) {
463476
op_array->refcount = (uint32_t*)(intptr_t)-1;
464477
SERIALIZE_PTR(op_array->literals);
@@ -478,7 +491,7 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
478491
zend_shared_alloc_register_xlat_entry(op_array->opcodes, op_array->opcodes);
479492
}
480493

481-
if (op_array->literals && !IS_SERIALIZED(op_array->literals)) {
494+
if (op_array->literals) {
482495
zval *p, *end;
483496

484497
SERIALIZE_PTR(op_array->literals);
@@ -491,7 +504,7 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
491504
}
492505
}
493506

494-
if (!IS_SERIALIZED(op_array->opcodes)) {
507+
{
495508
zend_op *opline, *end;
496509

497510
#if !ZEND_USE_ABS_CONST_ADDR
@@ -602,13 +615,6 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
602615
SERIALIZE_ATTRIBUTES(op_array->attributes);
603616
SERIALIZE_PTR(op_array->try_catch_array);
604617
SERIALIZE_PTR(op_array->prototype);
605-
606-
ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, &op_array->static_variables);
607-
if (op_array->fn_flags & ZEND_ACC_IMMUTABLE) {
608-
ZEND_MAP_PTR_INIT(op_array->run_time_cache, NULL);
609-
} else {
610-
SERIALIZE_PTR(ZEND_MAP_PTR(op_array->run_time_cache));
611-
}
612618
}
613619
}
614620

@@ -1213,7 +1219,13 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
12131219
zend_persistent_script *script,
12141220
void *buf)
12151221
{
1216-
if (op_array->static_variables && !IS_UNSERIALIZED(op_array->static_variables)) {
1222+
/* Check whether this op_array has already been unserialized. */
1223+
if (IS_UNSERIALIZED(op_array->opcodes)) {
1224+
ZEND_ASSERT(op_array->scope && "Only method op_arrays should be shared");
1225+
return;
1226+
}
1227+
1228+
if (op_array->static_variables) {
12171229
HashTable *ht;
12181230

12191231
UNSERIALIZE_PTR(op_array->static_variables);
@@ -1222,6 +1234,26 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
12221234
script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR);
12231235
}
12241236

1237+
if (op_array->fn_flags & ZEND_ACC_IMMUTABLE) {
1238+
if (op_array->static_variables) {
1239+
ZEND_MAP_PTR_NEW(op_array->static_variables_ptr);
1240+
} else {
1241+
ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, &op_array->static_variables);
1242+
}
1243+
ZEND_MAP_PTR_NEW(op_array->run_time_cache);
1244+
} else {
1245+
ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, &op_array->static_variables);
1246+
if (ZEND_MAP_PTR(op_array->run_time_cache)) {
1247+
if (script->corrupted) {
1248+
/* Not in SHM: Use serialized arena pointer. */
1249+
UNSERIALIZE_PTR(ZEND_MAP_PTR(op_array->run_time_cache));
1250+
} else {
1251+
/* In SHM: Allocate new pointer. */
1252+
ZEND_MAP_PTR_NEW(op_array->run_time_cache);
1253+
}
1254+
}
1255+
}
1256+
12251257
if (op_array->refcount) {
12261258
op_array->refcount = NULL;
12271259
UNSERIALIZE_PTR(op_array->literals);
@@ -1239,7 +1271,7 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
12391271
return;
12401272
}
12411273

1242-
if (op_array->literals && !IS_UNSERIALIZED(op_array->literals)) {
1274+
if (op_array->literals) {
12431275
zval *p, *end;
12441276

12451277
UNSERIALIZE_PTR(op_array->literals);
@@ -1251,7 +1283,7 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
12511283
}
12521284
}
12531285

1254-
if (!IS_UNSERIALIZED(op_array->opcodes)) {
1286+
{
12551287
zend_op *opline, *end;
12561288

12571289
UNSERIALIZE_PTR(op_array->opcodes);
@@ -1353,26 +1385,6 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
13531385
UNSERIALIZE_ATTRIBUTES(op_array->attributes);
13541386
UNSERIALIZE_PTR(op_array->try_catch_array);
13551387
UNSERIALIZE_PTR(op_array->prototype);
1356-
1357-
if (op_array->fn_flags & ZEND_ACC_IMMUTABLE) {
1358-
if (op_array->static_variables) {
1359-
ZEND_MAP_PTR_NEW(op_array->static_variables_ptr);
1360-
} else {
1361-
ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, &op_array->static_variables);
1362-
}
1363-
ZEND_MAP_PTR_NEW(op_array->run_time_cache);
1364-
} else {
1365-
ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, &op_array->static_variables);
1366-
if (ZEND_MAP_PTR(op_array->run_time_cache)) {
1367-
if (script->corrupted) {
1368-
/* Not in SHM: Use serialized arena pointer. */
1369-
UNSERIALIZE_PTR(ZEND_MAP_PTR(op_array->run_time_cache));
1370-
} else {
1371-
/* In SHM: Allocate new pointer. */
1372-
ZEND_MAP_PTR_NEW(op_array->run_time_cache);
1373-
}
1374-
}
1375-
}
13761388
}
13771389
}
13781390

0 commit comments

Comments
 (0)