Repository navigation
Fix Lua script argument corruption with mixed-key tag arrays - #188
Conversation
Co-authored-by: colinmollenhour <38738+colinmollenhour@users.noreply.github.com>
|
|
Co-authored-by: colinmollenhour <38738+colinmollenhour@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug where cache save operations with Lua scripts fail when tags contain mixed array keys (both numeric and string keys). This issue was observed in Magento 2.4.7+ where certain modules pass arrays like [0 => 'TAG1', 'EAV' => 'TAG2'], which causes Credis's _flattenArguments() to include string keys in the output, corrupting Lua script arguments.
Changes:
- Added
array_values()wrapper to ensure tags have sequential numeric keys before passing to Lua scripts - Added comprehensive test case to verify cache operations work correctly with mixed-key tag arrays
- Applied PSR-12 formatting improvements to switch statements
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
Cm/Cache/Backend/Redis.php |
Core fix: wraps tag deduplication with array_values() to ensure sequential keys; includes PSR-12 formatting improvements to switch statements |
tests/RedisBackendTest.php |
Adds testSaveWithMixedArrayKeys() test case that validates save, load, and tag querying operations with mixed-key tag arrays |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
LGTM, confirmed resolved. |
Fix for comment originally posted by @damienwebdev in #181 (comment)
Cache saves with Lua scripts fail when tags contain mixed array keys (e.g.,
[0 => 'TAG1', 'EAV' => 'TAG2']). Credis's_flattenArguments()adds string keys to the output, corrupting Lua arguments. Observed in Magento 2.4.7+ where certain modules pass such arrays.Changes
Core fix: Ensure tags have sequential numeric keys before passing to Credis
Test coverage: Added
testSaveWithMixedArrayKeys()to verify cache operations with mixed-key arrays work correctly.Technical Details
Without the fix,
_flattenArguments([0 => 'A', 'key' => 'B'])produces['A', 'key', 'B']instead of['A', 'B'], shifting Lua ARGV indices and causing operations to write to wrong keys or fail entirely.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/b3546ab487c0762c39f308dc1ec0ea2c461fc21a/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/clue/reactphp-ndjson/zipball/392dc165fce93b5bb5c637b67e59619223c931b0/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/colinmollenhour/credis/zipball/f4930b426f6b1238b687a1ffe6ee5af7f835b40a/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/x6np5P /usr/bin/composer install(http block)/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/composer/pcre/zipball/b2bed4734f0cc156ee1fe9c0da2550420d99a21e/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/x6np5P /usr/bin/composer install(http block)/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/composer/semver/zipball/198166618906cb2de69b95d7d47e5fa8aa1b2b95/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/composer/xdebug-handler/zipball/6c1925561632e83d60a44492e0b344cf48ab85ef/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/igorw/evenement/zipball/0a16b0d71ab13284339abb99d9d2bd813640efbc/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/myclabs/DeepCopy/zipball/07d290f0c47959fd5eed98c95ee5602db07e0b6a/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/nikic/PHP-Parser/zipball/dca41cd15c2ac9d055ad70dbfd011130757d1f82/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/x6np5P /usr/bin/composer install(http block)/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/php-fig/event-dispatcher/zipball/dbefd12671e8a14ec7f180cab83036ed26714bb0/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/reactphp/cache/zipball/d47c472b64aa5608225f47965a484b75c7817d5b/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/reactphp/child-process/zipball/970f0e71945556422ee4570ccbabaedc3cf04ad3/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/reactphp/dns/zipball/7562c05391f42701c1fccf189c8225fece1cd7c3/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/reactphp/event-loop/zipball/ba276bda6083df7e0050fd9b33f66ad7a4ac747a/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/reactphp/promise/zipball/23444f53a813a3296c1368bb104793ce8d88f04a/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/reactphp/socket/zipball/ef5b17b81f6f60504c539313f94f2d826c5faa08/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/reactphp/stream/zipball/1e5b0acb8fe55143b5b426817155190eb6f5b18d/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/2b56bea83a09de3ac06bb18b92f068e60cc6f50b/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/code-unit/zipball/1fc9f64c0927627ef78ba436c9b17d967e68e120/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/comparator/zipball/e4df00b9b3571187db2831ae9aada2c6efbd715d/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/complexity/zipball/25f207c40d62b8b7aa32f5ab026c53561964053a/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/diff/zipball/ba01945089c3a293b01ba9badc29ad55b106b0bc/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/exporter/zipball/14c6ba52f95a36c3d27c835d65efc7123c446e8c/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/global-state/zipball/b6781316bdcd28260904e7cc18ec983d0d2ef4f6/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/e1e4a170560925c26d424b6a03aed157e7dcc5c5/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/5c9eeac41b290a3712d88851518825ad78f45c71/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/b4f479ebdbf63ac605d183ece17d8d7fe49c15c7/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/85402a822d1ecf1db1096959413d35e1c37cf1a5/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/5a10147d0aaf65b58940a0b72f71c9ac0423cc67/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/php-timer/zipball/5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b36f02317466907a230d3aa1d34467041271ef4a/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/539c6691e0623af6dc6f9c20384c120f963465a0/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/console/zipball/41e38717ac1dd7a46b6bda7d6a82af2d98a78894/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/x6np5P /usr/bin/composer install(http block)/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/59eb412e93815df44f05f342958efa9f46b1e586/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/event-dispatcher/zipball/dc2c0eba1af673e736bb851d747d266108aea746/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/filesystem/zipball/d551b38811096d0be9c4691d406991b47c0c630a/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/finder/zipball/ad4daa7c38668dcb031e63bc99ea9bd42196a2cb/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/options-resolver/zipball/b38026df55197f9e39a44f3215788edf83187b80/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/polyfill-ctype/zipball/a3cc8b044a6ea513310cbd48ef7333b384945638/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/380872130d3a5dd3ace2f4010d95125fde5d5c70/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/3833d7255cc303546435cb650316bff708a1c75c/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/polyfill-php80/zipball/0cc9dd0f17f61d8131e7df6b84bd344899fe2608/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/polyfill-php81/zipball/4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/polyfill-php84/zipball/d8ced4d875142b6a7426000426b8abc631d6b191/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/x6np5P /usr/bin/composer install(http block)/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/process/zipball/608476f4604102976d687c483ac63a79ba18cc97/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/x6np5P /usr/bin/composer install(http block)/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/service-contracts/zipball/45112560a3ba2d715666a509a0bc9521d10b6c43/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/x6np5P /usr/bin/composer install(http block)/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/stopwatch/zipball/8a24af0a2e8a872fb745047180649b8418303084/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/x6np5P /usr/bin/composer install(http block)/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/symfony/string/zipball/1c4b10461bf2ec27537b5f36105337262f5f5d6f/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/theofidry/cpu-core-counter/zipball/db9508f7b1474469d9d3c53b86f817e344732678/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/theseer/tokenizer/zipball/b7489ce515e168639d17feec34b8847c326b0b3c/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/zf1s/zend-cache/zipball/af9ad663cc471b70b76140eda95501188ac4d6d4/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)https://api.github.com/repos/zf1s/zend-exception/zipball/2b0ab0dd6f615207f28c927123c9b8d9562a577a/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/p85FbR /usr/bin/composer install --no-interaction(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.