CMS MADE SIMPLE FORGE

CMSMSExt

 

[#12833] xt_utils::get_available_memory() fails to parse memory_limit with G or K suffixes

avatar
Created By: Magal (magallo)
Date Submitted: Mon May 18 07:17:39 -0400 2026

Assigned To: Fernando Morgado (JoMorg)
Version: 1.2.1
CMSMS Version: 2.2.22
Severity: Major
Resolution: None
State: Open
Summary:
xt_utils::get_available_memory() fails to parse memory_limit with G or K suffixes
Detailed Description:
The get_available_memory() method in lib/class.xt_utils.php uses intval() to
parse PHP's memory_limit ini value, then unconditionally multiplies by 1024 *
1024 (assuming megabytes). This breaks for valid php.ini values that use other
suffixes:

  - 2G → intval("2G") = 2 → calculated as 2MB instead of 2048MB
  - 1024K → intval("1024K") = 1024 → calculated as 1024MB instead of 1MB
  - -1 (unlimited) → max(1, -1) = 1 → calculated as 1MB

This causes SmartImage (and any module using this method) to incorrectly
reject images with "not enough memory" errors when memory_limit is set to a
value with a G suffix.

  Steps to reproduce:

  1. Set memory_limit = 2G in the Apache php.ini
  2. Use {SmartImage} tag on any image
  3. SmartImage reports insufficient memory for even small images

  Affected file: modules/CMSMSExt/lib/class.xt_utils.php, line 678

Suggested fix: Parse the suffix character (G/M/K) and convert to bytes
accordingly, and return PHP_INT_MAX when memory_limit is -1.


History