-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Extend map_ptr before copying class table #9188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--TEST-- | ||
Bug GH-9164: Segfault in zend_accel_class_hash_copy | ||
--EXTENSIONS-- | ||
opcache | ||
pcntl | ||
--INI-- | ||
opcache.enable_cli=1 | ||
--FILE-- | ||
<?php | ||
|
||
$incfile = __DIR__.'/gh9164.inc'; | ||
|
||
// Generate enough classes so that the out of bound access will cause a crash | ||
// without relying on assertion | ||
$fd = fopen($incfile, 'w'); | ||
fwrite($fd, "<?php\n"); | ||
for ($i = 0; $i < 4096; $i++) { | ||
fprintf($fd, "class FooBar%04d {}\n", $i); | ||
} | ||
fclose($fd); | ||
|
||
// Ensure cacheability | ||
touch($incfile, time() - 3600); | ||
|
||
$pid = pcntl_fork(); | ||
if ($pid == 0) { | ||
// Child: Declare classes to allocate CE cache slots. | ||
require $incfile; | ||
} else if ($pid > 0) { | ||
pcntl_wait($status); | ||
// Ensure that file has been cached. If not, this is testing nothing anymore. | ||
if (!isset(opcache_get_status()['scripts'][$incfile])) { | ||
print "File not cached\n"; | ||
} | ||
// Populates local cache | ||
require $incfile; | ||
var_dump(new FooBar4095); | ||
unlink($incfile); | ||
} else { | ||
echo "pcntl_fork() failed\n"; | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
object(FooBar4095)#%d (0) { | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,15 +347,11 @@ zend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script, | |
op_array = (zend_op_array *) emalloc(sizeof(zend_op_array)); | ||
*op_array = persistent_script->script.main_op_array; | ||
|
||
if (zend_hash_num_elements(&persistent_script->script.function_table) > 0) { | ||
zend_accel_function_hash_copy(CG(function_table), &persistent_script->script.function_table); | ||
} | ||
|
||
if (zend_hash_num_elements(&persistent_script->script.class_table) > 0) { | ||
zend_accel_class_hash_copy(CG(class_table), &persistent_script->script.class_table); | ||
} | ||
|
||
if (EXPECTED(from_shared_memory)) { | ||
if (ZCSG(map_ptr_last) > CG(map_ptr_last)) { | ||
zend_map_ptr_extend(ZCSG(map_ptr_last)); | ||
} | ||
Comment on lines
350
to
+353
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just moving the |
||
|
||
/* Register __COMPILER_HALT_OFFSET__ constant */ | ||
if (persistent_script->compiler_halt_offset != 0 && | ||
persistent_script->script.filename) { | ||
|
@@ -368,10 +364,14 @@ zend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script, | |
} | ||
zend_string_release_ex(name, 0); | ||
} | ||
} | ||
|
||
if (ZCSG(map_ptr_last) > CG(map_ptr_last)) { | ||
zend_map_ptr_extend(ZCSG(map_ptr_last)); | ||
} | ||
if (zend_hash_num_elements(&persistent_script->script.function_table) > 0) { | ||
zend_accel_function_hash_copy(CG(function_table), &persistent_script->script.function_table); | ||
} | ||
|
||
if (zend_hash_num_elements(&persistent_script->script.class_table) > 0) { | ||
zend_accel_class_hash_copy(CG(class_table), &persistent_script->script.class_table); | ||
} | ||
|
||
if (persistent_script->num_early_bindings) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't understand what do you do with this assertion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's asserting that the ce cache is valid, even if validation is skipped.