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

[zend-queue] prevent TypeError on md5 of non-string message #110

Merged
merged 1 commit into from
Oct 1, 2021

Conversation

falkenhawk
Copy link
Member

@falkenhawk falkenhawk commented Oct 1, 2021

Previous php versions emits a warning error when md5 is passed a non-string argument.
PHP 8.0 throws a TypeError and test failed with PHP Fatal error: Uncaught TypeError: md5(): Argument #1 ($string) must be of type string, array given (actually crashed the whole test run on php8 without any error message, had to run vendor/bin/phpunit tests/Zend/Queue/AllTests.php to isolate it.

Other adapters where md5 on a non-string value is attempted will also crash. (Zend_Queue_Adapter_Activemq and Zend_Queue_Adapter_Db) There is no easy way to fix this, keeping BC at the same time. Using a md5 hash there is wrong anyway - other adapters accept non-string values for a message, so even if the values are casted to string before md5 there be md5 clashes often (same hash in result) for objects or arrays "casted" fo string due to how php works internally (they should be probably serialized before calculating md5 hash, or using different hashing mechanism)

I decided to only add the throw on non-string value in Array adapter, what a test expects, and add string castints in Activemq and Db adapters so that md5 does not crash there. (and strlen in Activemq adapter)

Previous php versions emits a warning error when md5 is passed a non-string argument.
PHP throws a TypeError and test failed with `PHP Fatal error:  Uncaught TypeError: md5(): Argument #1 ($string) must be of type string, array given` (actually crashed the whole test run on php8 without any error message, had to run `vendor/bin/phpunit tests/Zend/Queue/AllTests.php` to isolate it.

Other adapters where md5 on a non-string value is attempted will also crash. (`Zend_Queue_Adapter_Activemq` and `Zend_Queue_Adapter_Db`) There is no easy way to fix this, keeping BC at the same time. Using a md5 hash there is wrong anyway - other adapters accept non-string values for a message, so even if the values are casted to string before md5 there be md5 clashes often (same hash in result) for objects or arrays "casted" fo string due to how php works internally (they should be probably serialized before calculating md5 hash, or using different hashing mechanism)

I decided to only add the throw on non-string value in Array adapter, what a test expects, and add string castints in Activemq and Db adapters so that md5 does not crash there. (and `strlen` in Activemq adapter)
@falkenhawk falkenhawk mentioned this pull request Oct 1, 2021
32 tasks
@falkenhawk falkenhawk merged commit 55f1b5e into master Oct 1, 2021
@falkenhawk falkenhawk deleted the fix-zend-queue-php8 branch October 1, 2021 11:47
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.

2 participants