Skip to content

Reflection*::__toString() truncates on null bytes #22681

Description

@DanielEScherzer

After #22658 I figured I would check some other things, the following all truncate on null bytes in user-controlled values

ReflectionClass::__toString() from doc comment
<?phpeval(<<<END/** F\0oo */class Demo {}END
);
$r = newReflectionClass('Demo');
echo$r;
var_dump( $r->getDocComment() );
ReflectionConstant::__toString() from constant name
<?phpdefine("F\0oo", true);
$r = newReflectionConstant("F\0oo");
echo$r;
var_dump( $r->getName() );
ReflectionClassConstant::__toString() from doc comment
<?phpeval(<<<ENDclass Demo { /** F\0oo */ public const DEMO = true;}END
);
$r = newReflectionClassConstant('Demo', 'DEMO');
echo$r;
var_dump( $r->getDocComment() );
ReflectionEnum::__toString() with enum case documentation
<?phpeval(<<<ENDenum Demo { /** F\0oo */ case DEMO;}END
);
$r = newReflectionEnum('Demo');
echo$r;
var_dump( newReflectionEnumUnitCase('Demo', 'DEMO')->getDocComment() );
ReflectionEnum::__toString() with backed enum value
<?phpeval(<<<ENDenum Demo: string { case DEMO = "F\0oo";}END
);
$r = newReflectionEnum('Demo');
echo$r;
var_dump( newReflectionEnumBackedCase('Demo', 'DEMO')->getBackingValue() );
ReflectionProperty::__toString() with doc comment
<?phpeval(<<<ENDclass Demo { /** F\0oo */ public \$prop;}END
);
$r = newReflectionProperty('Demo', 'prop');
echo$r;
var_dump( $r->getDocComment() );
ReflectionProperty::__toString() with dynamic property name
<?php$obj = (object)["F\0oo" => true];
$r = newReflectionProperty($obj, "F\0oo");
echo$r;
var_dump( $r->getDocComment() );
ReflectionExtension::__toString() with INI option value (also there is a weird `}` without a `{`, that should probably be fixed on master)
<?phpini_set('arg_separator.output', "f\0oo");
$r = newReflectionExtension('core');
$str = (string)$r;
$index = strpos($str, 'Entry [ arg_separator.output');
$str = substr($str, $index);
$index = strpos($str, 'Entry', 1);
$str = substr($str, 0, $index);
echo$str . "\n";
var_dump( $r->getINIEntries()['arg_separator.output'] );
ReflectionFunctionAbstract::__toString() with doc comment
<?phpeval(<<<END/** F\0oo */function demo() {}class Demo { /** F\0oo */ public function demo() {}}END
);
$r = newReflectionFunction('demo');
echo$r;
var_dump( $r->getDocComment() );
$r = newReflectionMethod(Demo::class, 'demo');
echo$r;
var_dump( $r->getDocComment() );

Metadata

Metadata

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions