Skip to content

Commit 33243da

Browse files
authored
Fix memory_limit calculation in modTransportPackage (#16820)
### What does it do? Re-implements the `_bytes` method using `ini_parse_quantity` introduced in PHP 8.2, providing a polyfill for use in PHP 8.1. ### Why is it needed? A php warning occurs (and gets logged in MODX as an error) because the `_bytes` function attempts to use the ini `memory_limit` value in a calculation without removing the modifier string (_e.g._, 128M *= 1024). This triggers the “A non-numeric value encountered” warning. ### How to test 1. Download any package before applying this PR fix. Note the warning in your MODX error log 2. Apply this PR and verify the warning no longer appears and that package downloads work as expected ### Related issue(s)/PR(s) Resolves #16504. Alternate solution for #16797 that supports all valid quantities that might appear in the ini `memory_limit` value.
1 parent af7a969 commit 33243da

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
"ext-xml": "*",
7777
"ext-zip": "*",
7878
"ext-xmlwriter": "*",
79-
"ext-fileinfo": "*"
79+
"ext-fileinfo": "*",
80+
"symfony/polyfill-php82": "^1.33"
8081
},
8182
"suggest": {
8283
"ext-imagick": "To process images in a more advanced way",

core/src/Revolution/Transport/modTransportPackage.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -746,20 +746,7 @@ public function findResolution($package, $constraint, &$provider = null)
746746
*/
747747
protected function _bytes($value)
748748
{
749-
$value = trim($value);
750-
$modifier = strtolower($value[strlen($value) - 1]);
751-
switch ($modifier) {
752-
case 'g':
753-
$value *= 1024;
754-
// no break
755-
case 'm':
756-
$value *= 1024;
757-
// no break
758-
case 'k':
759-
$value *= 1024;
760-
}
761-
762-
return $value;
749+
return ini_parse_quantity(trim($value));
763750
}
764751

765752
/**

0 commit comments

Comments
 (0)