Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/standard/base64_encode.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function execute(Frame $frame): void
if (1 !== \count($frame->calledArgs)) {
throw new \LogicException('base64_encode() requires exactly one argument in this compiler build');
}
$data = VmString::coerceStringBuiltinArg($frame->calledArgs[0], 'base64_encode', 0, 'string');
$data = VmString::coerceTypedStringBuiltinArg($frame->calledArgs[0], 'base64_encode', 0, 'string');
BuiltinExecute::writeReturn($frame, static function ($ret) use ($data): void {
$ret->string(VmString::base64_encode($data));
});
Expand All @@ -49,7 +49,7 @@ public function call(Context $context, JITVariable ...$args): Value

return $context->builder->call(
$context->lookupFunction('__compiler_base64_encode'),
JitStringBuiltinArg::lower($context, $args[0], 'base64_encode', 0, 'string')
JitStringBuiltinArg::lowerTypedString($context, $args[0], 'base64_encode', 0, 'string')
);
}
}
4 changes: 2 additions & 2 deletions ext/standard/bin2hex.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function execute(Frame $frame): void
if (1 !== \count($frame->calledArgs)) {
throw new \LogicException('bin2hex() requires exactly one argument');
}
$data = VmString::coerceStringBuiltinArg($frame->calledArgs[0], 'bin2hex', 0, 'string');
$data = VmString::coerceTypedStringBuiltinArg($frame->calledArgs[0], 'bin2hex', 0, 'string');
BuiltinExecute::writeReturn($frame, static function ($ret) use ($data): void {
$ret->string(VmString::bin2hex($data));
});
Expand All @@ -48,7 +48,7 @@ public function call(Context $context, JITVariable ...$args): Value

return $context->builder->call(
$context->lookupFunction('__compiler_bin2hex'),
JitStringBuiltinArg::lower($context, $args[0], 'bin2hex', 0, 'string')
JitStringBuiltinArg::lowerTypedString($context, $args[0], 'bin2hex', 0, 'string')
);
}
}
4 changes: 2 additions & 2 deletions ext/standard/quoted_printable_decode.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function execute(Frame $frame): void
if (1 !== \count($frame->calledArgs)) {
throw new \LogicException('quoted_printable_decode() requires exactly one argument in this compiler build');
}
$data = VmString::coerceStringBuiltinArg(
$data = VmString::coerceTypedStringBuiltinArg(
$frame->calledArgs[0],
'quoted_printable_decode',
0,
Expand All @@ -43,7 +43,7 @@ public function call(Context $context, JITVariable ...$args): Value
}
return JitQuotedPrintableDecode::decode(
$context,
JitStringBuiltinArg::lower($context, $args[0], 'quoted_printable_decode', 0, 'string'),
JitStringBuiltinArg::lowerTypedString($context, $args[0], 'quoted_printable_decode', 0, 'string'),
$args[0]
);
}
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/quoted_printable_encode.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function execute(Frame $frame): void
if (1 !== \count($frame->calledArgs)) {
throw new \LogicException('quoted_printable_encode() requires exactly one argument in this compiler build');
}
$data = VmString::coerceStringBuiltinArg(
$data = VmString::coerceTypedStringBuiltinArg(
$frame->calledArgs[0],
'quoted_printable_encode',
0,
Expand All @@ -43,7 +43,7 @@ public function call(Context $context, JITVariable ...$args): Value
}
return JitQuotedPrintableEncode::encode(
$context,
JitStringBuiltinArg::lower($context, $args[0], 'quoted_printable_encode', 0, 'string'),
JitStringBuiltinArg::lowerTypedString($context, $args[0], 'quoted_printable_encode', 0, 'string'),
$args[0]
);
}
Expand Down
17 changes: 17 additions & 0 deletions test/compliance/cases/stdlib/encoding_null.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
stdlib encoding/binary builtins — null $string TypeError (#18252, ext/standard/string.c, base64.c)
--FILE--
<?php
foreach (['bin2hex', 'base64_encode', 'quoted_printable_encode', 'quoted_printable_decode'] as $fn) {
try {
$fn(null);
echo "{$fn}: uncaught\n";
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
}
--EXPECT--
bin2hex(): Argument #1 ($string) must be of type string, null given
base64_encode(): Argument #1 ($string) must be of type string, null given
quoted_printable_encode(): Argument #1 ($string) must be of type string, null given
quoted_printable_decode(): Argument #1 ($string) must be of type string, null given
18 changes: 18 additions & 0 deletions test/compliance/cases/stdlib/encoding_null_jit.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
stdlib encoding/binary builtins — null $string TypeError JIT (#18252, ext/standard/string.c, base64.c)
--JIT--
--FILE--
<?php
foreach (['bin2hex', 'base64_encode', 'quoted_printable_encode', 'quoted_printable_decode'] as $fn) {
try {
$fn(null);
echo "{$fn}: uncaught\n";
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
}
--EXPECT--
bin2hex(): Argument #1 ($string) must be of type string, null given
base64_encode(): Argument #1 ($string) must be of type string, null given
quoted_printable_encode(): Argument #1 ($string) must be of type string, null given
quoted_printable_decode(): Argument #1 ($string) must be of type string, null given
12 changes: 12 additions & 0 deletions test/repro/maintainer_gap_encoding_binary_null.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

foreach (['bin2hex', 'base64_encode', 'quoted_printable_encode', 'quoted_printable_decode'] as $fn) {
try {
$fn(null);
echo "{$fn}: uncaught\n";
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
}
2 changes: 2 additions & 0 deletions test/unit/Bin2hexRuntimeShrinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public function testStringBin2hexUsesJitHelperNotInlineLlvm(): void
$builtin = (string) file_get_contents(__DIR__.'/../../ext/standard/bin2hex.php');
$this->assertStringContainsString('StringBin2hex::ensureLinked', $builtin);
$this->assertStringContainsString('__compiler_bin2hex', $builtin);
$this->assertStringContainsString('coerceTypedStringBuiltinArg', $builtin);
$this->assertStringContainsString('lowerTypedString', $builtin);
}

public function testBin2hexJitHelperDelegatesToVmString(): void
Expand Down