Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bf76480

Browse filesBrowse files
[VarDumper] Fix FFI caster test
1 parent 7b53770 commit bf76480
Copy full SHA for bf76480

File tree

2 files changed

+13
-18
lines changed
Filter options

2 files changed

+13
-18
lines changed

‎src/Symfony/Component/VarDumper/Caster/FFICaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/FFICaster.php
+11-3Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,20 @@ private static function castFFIPointer(Stub $stub, CType $type, ?CData $data = n
115115
private static function castFFIStringValue(CData $data): string|CutStub
116116
{
117117
$result = [];
118+
$ffi = \FFI::cdef(<<<C
119+
bool is_zend_mm(void);
120+
bool is_zend_ptr(const void *ptr);
121+
C);
118122

119123
for ($i = 0; $i < self::MAX_STRING_LENGTH; ++$i) {
120-
$result[$i] = $data[$i];
124+
if ($ffi->is_zend_ptr($data) && $ffi->is_zend_mm()) {
125+
$result[$i] = $data[$i];
121126

122-
if ("\0" === $result[$i]) {
123-
return implode('', $result);
127+
if ("\0" === $data[$i]) {
128+
return implode('', $result);
129+
}
130+
} else {
131+
break;
124132
}
125133
}
126134

‎src/Symfony/Component/VarDumper/Tests/Caster/FFICasterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Tests/Caster/FFICasterTest.php
+2-15Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\VarDumper\Tests\Caster;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\VarDumper\Caster\FFICaster;
1615
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
1716

1817
/**
@@ -191,25 +190,13 @@ public function testCastCuttedPointerToChar()
191190
PHP, $pointer);
192191
}
193192

194-
/**
195-
* It is worth noting that such a test can cause SIGSEGV, as it breaks
196-
* into "foreign" memory. However, this is only theoretical, since
197-
* memory is allocated within the PHP process and almost always "garbage
198-
* data" will be read from the PHP process itself.
199-
*
200-
* If this test fails for some reason, please report it: We may have to
201-
* disable the dumping of strings ("char*") feature in VarDumper.
202-
*
203-
* @see FFICaster::castFFIStringValue()
204-
*/
205193
public function testCastNonTrailingCharPointer()
206194
{
207195
$actualMessage = 'Hello World!';
208196
$actualLength = \strlen($actualMessage);
209197

210-
$string = \FFI::cdef()->new('char['.$actualLength.']');
198+
$string = \FFI::cdef()->new('char['.($actualLength + 1).']');
211199
$pointer = \FFI::addr($string[0]);
212-
213200
\FFI::memcpy($pointer, $actualMessage, $actualLength);
214201

215202
// Remove automatically addition of the trailing "\0" and remove trailing "\0"
@@ -218,7 +205,7 @@ public function testCastNonTrailingCharPointer()
218205

219206
$this->assertDumpMatchesFormat(<<<PHP
220207
FFI\CData<char*> size 8 align 8 {
221-
cdata: "$actualMessage%s"
208+
cdata: %A"$actualMessage%s"
222209
}
223210
PHP, $pointer);
224211
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.