Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR: A field whose name matches a protected or private method on the entry crashes a request with memory exhaustion. Augmentation only checks if the method exists, then calls it from an outside scope that can't reach it, so PHP routes it to
__call()and it augments the same handle forever, resulting in an infinite loop + crash. This PR requires the method to be public for it to be considered.Problem
When augmenting a handle,
AbstractAugmentedlooks for a method of the same name on the entry/term/asset/etc and calls it instead of reading the stored value. I.e. a publicisSold()method overrides anis_soldfield.The check here is
method_exists(), which is true for both protected and private methods. However the call happens from outside the entry class:$this->data->$method(). PHP won't call the non-public method and forwards to__call()instead. Augmentables then useHasAugmentedInstance::__call(), which augments that same handle again. Nothing stops the loop, so the request runs out of memory.Example
This adds an internal helper method for coercing a type. It never was meant for actual augmentation, but crashes.
Fix
Only treat the method as a match if it's public/reachable. Checked via
ReflectionMethodrather thanis_callable()since that also returnstruefor unreachable methods. Cached to avoid repetitive lookups.Scope
This only changes the lookup on the entry. The separate lookup for methods on the
Augmented*class itself is left alone on purpose: those are called from inside that class, so its own protected methods are reachable and need to keep working (permalink(),mount(),updatedBy()). There's a test that covers that.Not breaking
Before this change, a non-public method matching a key could only and in an error: either the infinite loop above or
Error: Call to protected method. There was no version of this that worked so nothing can be relying on it. Public methods still override their field, exactly as before.