Repository navigation
JIT: Fix FETCH_DIM_IS ignoring leading-numeric string offsets #25298
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
Open
jorgsowa
wants to merge
2
commits into
php:PHP-8.4
Choose a base branch
from
jorgsowa:fix-jit-fetch-dim-is-string-offset
base: PHP-8.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+199
−7
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,39 @@ | ||
| --TEST-- | ||
| JIT FETCH_DIM_IS: string offsets given as strings behave like the VM | ||
| --INI-- | ||
| opcache.enable=1 | ||
| opcache.enable_cli=1 | ||
| opcache.jit=function | ||
| opcache.file_update_protection=0 | ||
| --EXTENSIONS-- | ||
| opcache | ||
| --FILE-- | ||
| <?php | ||
| function test(string $s, string $k) { | ||
| return $s[$k] ?? "default"; | ||
| } | ||
|
|
||
| foreach (["1", "-1", "1 ", " 1", "1x", "-1x", "9x", "x", "", "1.5", "1.5x", "99999999999999999999"] as $k) { | ||
| echo var_export($k, true), ": "; | ||
| var_dump(test("abc", $k)); | ||
| } | ||
| ?> | ||
| --EXPECTF-- | ||
| '1': string(1) "b" | ||
| '-1': string(1) "c" | ||
| '1 ': string(1) "b" | ||
| ' 1': string(1) "b" | ||
| '1x': | ||
| Warning: Illegal string offset "1x" in %s on line %d | ||
| string(1) "b" | ||
| '-1x': | ||
| Warning: Illegal string offset "-1x" in %s on line %d | ||
| string(1) "c" | ||
| '9x': | ||
| Warning: Illegal string offset "9x" in %s on line %d | ||
| string(7) "default" | ||
| 'x': string(7) "default" | ||
| '': string(7) "default" | ||
| '1.5': string(7) "default" | ||
| '1.5x': string(7) "default" | ||
| '99999999999999999999': string(7) "default" |
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,35 @@ | ||
| --TEST-- | ||
| JIT FETCH_DIM_IS: leading-numeric string offset conversion may throw | ||
| --INI-- | ||
| opcache.enable=1 | ||
| opcache.enable_cli=1 | ||
| opcache.jit=function | ||
| opcache.file_update_protection=0 | ||
| --EXTENSIONS-- | ||
| opcache | ||
| --FILE-- | ||
| <?php | ||
| set_error_handler(function ($errno, $errstr) { | ||
| throw new Exception($errstr); | ||
| }); | ||
|
|
||
| function make(int $n) { | ||
| return str_repeat("abc", $n); | ||
| } | ||
|
|
||
| function consume($v) { | ||
| echo "unreachable\n"; | ||
| } | ||
|
|
||
| function test(string $s) { | ||
| consume($s["1x"] ?? "default"); | ||
| } | ||
|
|
||
| try { | ||
| test(make(2)); | ||
| } catch (Exception $e) { | ||
| echo $e::class, ": ", $e->getMessage(), "\n"; | ||
| } | ||
| ?> | ||
| --EXPECT-- | ||
| Exception: Illegal string offset "1x" |
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,35 @@ | ||
| --TEST-- | ||
| JIT FETCH_DIM_IS: leading-numeric string offset may throw between call arguments | ||
| --INI-- | ||
| opcache.enable=1 | ||
| opcache.enable_cli=1 | ||
| opcache.jit=function | ||
| opcache.file_update_protection=0 | ||
| --EXTENSIONS-- | ||
| opcache | ||
| --FILE-- | ||
| <?php | ||
| set_error_handler(function ($errno, $errstr) { | ||
| throw new Exception($errstr); | ||
| }); | ||
|
|
||
| function make(int $n) { | ||
| return str_repeat("abc", $n); | ||
| } | ||
|
|
||
| function consume($a, $b) { | ||
| echo "unreachable\n"; | ||
| } | ||
|
|
||
| function test(string $s, string $t) { | ||
| consume($t, isset($s["1x"][0])); | ||
| } | ||
|
|
||
| try { | ||
| test(make(2), make(3)); | ||
| } catch (Exception $e) { | ||
| echo $e::class, ": ", $e->getMessage(), "\n"; | ||
| } | ||
| ?> | ||
| --EXPECT-- | ||
| Exception: Illegal string offset "1x" |
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,31 @@ | ||
| --TEST-- | ||
| JIT FETCH_DIM_IS: leading-numeric string offset warning may release the string | ||
| --INI-- | ||
| opcache.enable=1 | ||
| opcache.enable_cli=1 | ||
| opcache.jit=function | ||
| opcache.file_update_protection=0 | ||
| --EXTENSIONS-- | ||
| opcache | ||
| --FILE-- | ||
| <?php | ||
| set_error_handler(function ($errno, $errstr) { | ||
| echo "Warning: $errstr\n"; | ||
| $GLOBALS['s'] = null; | ||
| }); | ||
|
|
||
| function make(int $n) { | ||
| return str_repeat("abc", $n); | ||
| } | ||
|
|
||
| function test() { | ||
| global $s; | ||
| return $s["1x"] ?? "default"; | ||
| } | ||
|
|
||
| $s = make(2); | ||
| var_dump(test()); | ||
| ?> | ||
| --EXPECT-- | ||
| Warning: Illegal string offset "1x" | ||
| string(7) "default" |
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,34 @@ | ||
| --TEST-- | ||
| DCE must not remove FETCH_DIM_IS of a nested isset()/empty() with a leading-numeric string offset | ||
| --INI-- | ||
| opcache.enable=1 | ||
| opcache.enable_cli=1 | ||
| opcache.optimization_level=-1 | ||
| opcache.file_update_protection=0 | ||
| --EXTENSIONS-- | ||
| opcache | ||
| --FILE-- | ||
| <?php | ||
| set_error_handler(function ($errno, $errstr) { | ||
| throw new Exception($errstr); | ||
| }); | ||
|
|
||
| function test_isset(string $s) { | ||
| $x = isset($s["1x"][0]); | ||
| } | ||
|
|
||
| function test_empty(string $s) { | ||
| $x = empty($s["1x"][0]); | ||
| } | ||
|
|
||
| foreach (['test_isset', 'test_empty'] as $f) { | ||
| try { | ||
| $f("abc"); | ||
| } catch (Exception $e) { | ||
| echo $e::class, ": ", $e->getMessage(), "\n"; | ||
| } | ||
| } | ||
| ?> | ||
| --EXPECT-- | ||
| Exception: Illegal string offset "1x" | ||
| Exception: Illegal string offset "1x" |
Oops, something went wrong.
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.
The undefined-variable warning here can free
strthe same way: withglobal $s; return $s[$undef] ?? 1;and an error handler doing$GLOBALS['s'] = null, function JIT then reads the freed string (valgrind; PHP-8.4 has it without this PR too). Could the new guard cover this case as well, like the VM's IS_UNDEF branch does? The VM's own trailing-data warning in zend_fetch_dimension_address_read() has no guard either and shows the same invalid read without opcache.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 created separate PR for this bug fix: #25329
It's valid bug, but I would like to keep all fixes separately. It's better for clearer git history.