Skip to content
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

Fix issue with modified backtrace #250

Merged
merged 1 commit into from
Aug 15, 2020
Merged

Conversation

jaapio
Copy link
Member

@jaapio jaapio commented Aug 12, 2020

php allows the backtrace arguments to be modified via the
backtrace. By using array_map we make sure that we do not overwrite
references.

fixes #249

php allows the backtrace arguments to be modified via the
backtrace. By using array_map we make sure that we do not overwrite
references.
@@ -15,4 +15,8 @@
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix">
<exclude-pattern>*/src/*/Abstract*.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod">
Copy link
Contributor

@williamdes williamdes Aug 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be moved to the source file, but it depends on your code policy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My proposed change would avoid this error

static function (array $call) use ($flatten) : array {
array_walk_recursive($call['args'], $flatten);
function (array $call) : array {
$call['args'] = array_map([$this, 'flattenArguments'], $call['args']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give the php version requirements I would recommend (not tested):
https://github.com/phpDocumentor/ReflectionDocBlock/blob/master/composer.json#L17

Suggested change
$call['args'] = array_map([$this, 'flattenArguments'], $call['args']);
$call['args'] = array_map(function($value) { return $this->flattenArguments($value); }, $call['args']);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👎 for changing this. The array-callable syntax is much shorter and clearer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, for me this syntax is "compilation" compatible and explicit for any code searcher or analyser :)
Don't you agree?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And that would remove the need of ref="SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod">

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both can be formally detected. I guess it just hasn't been implemented by that code style package. psalm itself certainly recognises uses like that, in it's core stuff.

@jaapio
Copy link
Member Author

jaapio commented Aug 12, 2020

@williamdes thanks for the review, are you able to test this with doctum?

@williamdes
Copy link
Contributor

@williamdes thanks for the review, are you able to test this with doctum?

Not yet, it will take me some time to test it because I can not reproduce it locally..
I will need to hack a phar and try on Travis CI phpMyAdmin

@jaapio
Copy link
Member Author

jaapio commented Aug 13, 2020

If you can provide a phar I can reproduce the issue in docker😁

@williamdes
Copy link
Contributor

If you can provide a phar I can reproduce the issue in docker😁

Well if you succeed that would help me because I could not replicate this on my workstation or docker instances

Follow nikic/PHP-Parser#687 (comment) to replicate the issue, @nikic seems to have reproduced it

@jaapio
Copy link
Member Author

jaapio commented Aug 13, 2020

That's what I already did, but can you provide me a phar with the fix included?

@williamdes
Copy link
Contributor

That's what I already did, but can you provide me a phar with the fix included?

Sure, here it is: https://doctum.long-term.support/releases/5.0.2-dev/doctum.phar

You can see on my manifest diff that I applied your patch code-lts/doctum@d2695c0#diff-d313403d9a8ddaf7d325ee4001bd3fb6

@williamdes
Copy link
Contributor

The patch works fine on TravisCI ! 🚀
https://travis-ci.org/github/williamdes/phpmyadmintest/jobs/709799927

@jaapio jaapio merged commit d870572 into master Aug 15, 2020
@jaapio jaapio deleted the fix/modified-backtrace-arguments branch August 15, 2020 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

InvalidTag::flattenExceptionBacktrace() corrupts reference arguments
3 participants