-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Prevent GetSetMethodNormalizer
from creating invalid magic method call
#48233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Serializer] Prevent GetSetMethodNormalizer
from creating invalid magic method call
#48233
Conversation
GetSetMethodNormalizer
from creating invalid magic method call
src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php
Outdated
Show resolved
Hide resolved
Should the |
@xabbuh denormalization does not seem to be affected. |
Doe we have a test case for this? Otherwise it could be helpful to add one in this PR |
I was wrong! Good catch @xabbuh. Managed to reproduce it, but had to take a different approach: |
Thank you @klaussilveira. |
@klaussilveira Sorry for being so late with my review, but I do not really see when or why a |
…ction exceptions (xabbuh) This PR was merged into the 5.4 branch. Discussion ---------- [Serializer] use method_exists() instead of catching reflection exceptions | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | #48233 (comment) | License | MIT | Doc PR | Commits ------- 0e883a9 use method_exists() instead of catching reflection exceptions
When serializing an object that has an
isser
for a property, but not agetter
, and the object happens to have a__call
magic method, theGetSetMethodNormalizer
will attempt to call the magic method with the attribute. This may cause unexpected behavior, or, a fatal. It depends on the__call
implementation.This undefined behavior is caused by the use of
is_callable
ongetAttributeValue
, which will return true since there is a__call
implementation. The correct behavior can be achieved by usingmethod_exists
instead. A test case has been added that illustrates the issue.