Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 705a4f7

Browse files
committed
bug #20146 [Validator] Prevent infinite loop in PropertyMetadata (wesleylancel)
This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #20146). Discussion ---------- [Validator] Prevent infinite loop in PropertyMetadata | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets |n/a | License | MIT | Doc PR | n/a This commit fixes a possible infinite loop in PropertyMetadata when the PropertyMetadata class was constructed with an existing property of class and later used (after being serialized and cached) on that same class while that property no longer existing. `get_parent_class` will return false when there is no parent class and `property_existing` will then keeping return false causing the `while` loop to be infinite. Commits ------- c1ae7b6 Prevent infinite loop in PropertyMetadata
2 parents ab6f181 + c1ae7b6 commit 705a4f7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Symfony/Component/Validator/Mapping/PropertyMetadata.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ public function getPropertyValue($object)
5858
*/
5959
protected function newReflectionMember($objectOrClassName)
6060
{
61+
$originalClass = is_string($objectOrClassName) ? $objectOrClassName : get_class($objectOrClassName);
62+
6163
while (!property_exists($objectOrClassName, $this->getName())) {
6264
$objectOrClassName = get_parent_class($objectOrClassName);
65+
66+
if (false === $objectOrClassName) {
67+
throw new ValidatorException(sprintf('Property "%s" does not exist in class "%s"', $this->getName(), $originalClass));
68+
}
6369
}
6470

6571
$member = new \ReflectionProperty($objectOrClassName, $this->getName());

src/Symfony/Component/Validator/Tests/Mapping/PropertyMetadataTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,14 @@ public function testGetPropertyValueFromOverriddenPrivateProperty()
4242
$this->assertTrue($metadata->isPublic($entity));
4343
$this->assertEquals('Overridden data', $metadata->getPropertyValue($entity));
4444
}
45+
46+
public function testGetPropertyValueFromRemovedProperty()
47+
{
48+
$entity = new Entity('foobar');
49+
$metadata = new PropertyMetadata(self::CLASSNAME, 'internal');
50+
$metadata->name = 'test';
51+
52+
$this->setExpectedException('Symfony\Component\Validator\Exception\ValidatorException');
53+
$metadata->getPropertyValue($entity);
54+
}
4555
}

0 commit comments

Comments
 (0)