-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to allow stack extension (#131)
- Loading branch information
1 parent
7010de9
commit 85d4d59
Showing
12 changed files
with
276 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,41 @@ | ||
--TEST-- | ||
Check if pre hook can expand params of function when that requires extending the stack | ||
--EXTENSIONS-- | ||
opentelemetry | ||
--INI-- | ||
opentelemetry.allow_stack_extension=On | ||
--FILE-- | ||
<?php | ||
OpenTelemetry\Instrumentation\hook( | ||
null, | ||
'helloWorld', | ||
pre: function($instance, array $params) { | ||
return [$params[0], 'b', 'c', 'd', 'e', 'f', 'g', 'h']; | ||
}, | ||
post: fn() => null | ||
); | ||
|
||
function helloWorld($a, $b) { | ||
var_dump(func_get_args()); | ||
} | ||
helloWorld('a'); | ||
?> | ||
--EXPECTF-- | ||
array(8) { | ||
[0]=> | ||
string(1) "a" | ||
[1]=> | ||
string(1) "b" | ||
[2]=> | ||
string(1) "c" | ||
[3]=> | ||
string(1) "d" | ||
[4]=> | ||
string(1) "e" | ||
[5]=> | ||
string(1) "f" | ||
[6]=> | ||
string(1) "g" | ||
[7]=> | ||
string(1) "h" | ||
} |
This file contains 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,26 @@ | ||
--TEST-- | ||
Check if pre hook can expand params of internal function when that requires extending the stack | ||
--SKIPIF-- | ||
<?php if (PHP_VERSION_ID < 80200) die('skip requires PHP >= 8.2'); ?> | ||
--EXTENSIONS-- | ||
opentelemetry | ||
--INI-- | ||
opentelemetry.allow_stack_extension=On | ||
--FILE-- | ||
<?php | ||
OpenTelemetry\Instrumentation\hook( | ||
null, | ||
'array_slice', | ||
pre: function(null $instance, array $params) { | ||
return [$params[0], $params[1], 1, true]; | ||
}, | ||
post: fn() => null | ||
); | ||
|
||
var_dump(array_slice([1,2,3], 1)); | ||
?> | ||
--EXPECTF-- | ||
array(1) { | ||
[1]=> | ||
int(2) | ||
} |
This file contains 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-- | ||
Check if pre hook can expand params of internal function when that requires extending the stack (many params) | ||
--DESCRIPTION-- | ||
This will add MANY extra arguments to an internal function, making it fail with an error. | ||
However, the purpose of this test is to just make sure it does not somehow corrupt the stack | ||
and cause a crash with a large number of extra parameters. | ||
--SKIPIF-- | ||
<?php if (PHP_VERSION_ID < 80200) die('skip requires PHP >= 8.2'); ?> | ||
--EXTENSIONS-- | ||
opentelemetry | ||
--INI-- | ||
opentelemetry.allow_stack_extension=On | ||
--FILE-- | ||
<?php | ||
OpenTelemetry\Instrumentation\hook( | ||
null, | ||
'array_slice', | ||
pre: function(null $instance, array $params) { | ||
return [$params[0], $params[1], 1, true, true, true, true, true, true, true, true, true, true]; | ||
}, | ||
post: fn() => null | ||
); | ||
|
||
var_dump(array_slice([1,2,3], 1)); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Uncaught ArgumentCountError: array_slice() expects at most 4 arguments, 13 given in %s | ||
Stack trace: | ||
#0 %s: array_slice(Array, 1, 1, true, true, true, true, true, true, true, true, true, true) | ||
#1 {main} | ||
thrown in %s on line %d |
This file contains 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,62 @@ | ||
--TEST-- | ||
Check if pre hook can expand params of function when that requires extending the stack only until hardcoded limit | ||
--EXTENSIONS-- | ||
opentelemetry | ||
--INI-- | ||
opentelemetry.allow_stack_extension=On | ||
--FILE-- | ||
<?php | ||
OpenTelemetry\Instrumentation\hook( | ||
null, | ||
'helloWorld', | ||
pre: function($instance, array $params) { | ||
return [$params[0], 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u']; | ||
}, | ||
post: fn() => null | ||
); | ||
|
||
function helloWorld($a, $b) { | ||
var_dump(func_get_args()); | ||
} | ||
helloWorld('a'); | ||
?> | ||
--EXPECTF-- | ||
Warning: helloWorld(): OpenTelemetry: pre hook invalid argument index 18 - exceeds built-in stack extension limit, class=null function=helloWorld in %s | ||
array(18) { | ||
[0]=> | ||
string(1) "a" | ||
[1]=> | ||
string(1) "b" | ||
[2]=> | ||
string(1) "c" | ||
[3]=> | ||
string(1) "d" | ||
[4]=> | ||
string(1) "e" | ||
[5]=> | ||
string(1) "f" | ||
[6]=> | ||
string(1) "g" | ||
[7]=> | ||
string(1) "h" | ||
[8]=> | ||
string(1) "i" | ||
[9]=> | ||
string(1) "j" | ||
[10]=> | ||
string(1) "k" | ||
[11]=> | ||
string(1) "l" | ||
[12]=> | ||
string(1) "m" | ||
[13]=> | ||
string(1) "n" | ||
[14]=> | ||
string(1) "o" | ||
[15]=> | ||
string(1) "p" | ||
[16]=> | ||
string(1) "q" | ||
[17]=> | ||
string(1) "r" | ||
} |
This file contains 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 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
Oops, something went wrong.