Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

GD2 Adapter PHP memory_limit #481

wants to merge 2 commits into


None yet
3 participants

When performing manipulation on images the PHP memory limit is checked.

When the available memory is less than the required an error "Memory limit has been reached" is thrown.
This is seen by users when uploading product images though it also happens background processes happen (e.g. when thumbnails are generated).

In lib/Magento/Image/Adapter/Gd2.php the functions _isMemoryLimitReached and _convertToByte do this checking.

_isMemoryLimitReached retrieves PHP's memory_limit value. It passes this directly to _convertToByte without any sanity checking.

_convertToByte assumes that the value is an integer in bytes (or has a suffix indicating units).

Valid values for PHP > 5.1.0 memory_limit are:

-1 = no limit
positive integers without suffix = value in bytes
positive integers with the upper or lower case suffixes k, m, g = value in kilobytes, megabytes and gigabytes.

References for this: http://nz1.php.net/manual/en/ini.core.php#ini.memory-limit and http://nz1.php.net/manual/en/faq.using.php#faq.using.shorthandbytes

With the current implementation if the memory_limit is set to the valid value of -1 the "Memory limit has been reached" error is returned incorrectly.

The suffixes currently parsed in _convertToByte are "KB" and "M". As above "KB" is not a valid suffix. "G", for gigabytes, is supported by PHP but omitted from Magento check which will lead to the "Memory limit has been reached" error.

This pull request changes KB suffix to the valid K, though this isn't likely to be used it should be correct.

It also returns false to _isMemoryLimitReached when the value of PHP's memory_limit is -1.

(This issue also exists in 1.8: http://www.magentocommerce.com/bug-tracking/issue?issue=16071)

Hello @rjocoleman . thank you for your contribution! The team will look at it and we will update you once the analysis is complete.

magento-team added a commit that referenced this pull request Apr 11, 2014
* Framework Improvements:
  * Eliminated the StoreConfig class, and ability to work with Configuration through the Store object. Scope Config was introduced instead.
  * Fixed performance degradation caused by DI argument processors
  * Covered Magento library components with unit tests:
     * Magento/App/Request
     * Magento/App/Resource directory and Magento/App/Resource.php
     * Magento/App/Response
     * Magento/App/Route
     * Magento/App/Router
     * Magento/App/Http.php
     * Magento/Translate.php
  * Improved the Web API framework based on Customer Service
  * Updated the API Service Exception Handling
  * Changed the conventional notation of Vendor name in theme path: from `app/design/<area>/<vendor>_<theme>` to `app/design/<area>/<vendor>/<theme>`
  * Renamed the 3DSecure library to CardinalCommerce, and removed the unused flex library
* Themes update:
  * Updated the look&feel of the Admin theme
* Modularity improvements:
  * Introduced a new Store module. Moved all Store related logic from Magento_Core to Magento_Store
  * Moved the library part of the Config component from the Magento_Core module to the library
  * Moved the Session related logic from the Magento_Core module to the library
  * Moved the abstract logic related to Magento "Module" from Magento_Core to the library
  * Moved the form key related functionality to the library
  * Introduced a new Magento_UrlRewrite module and moved related classes from Magento_Core to the new module
  * Moved the resource model to Magento_Install module
  * Eliminated the Core\Helper\Js class
  * Moved the Email related logic from Magento_Core module to Magento_Email module
  * Moved the Cache related logic from the Magento_Core module to the library
  * Resolved issues which appeared when an order had been placed before the Magento_Payment module was disabled
  * Eliminated Magento_Catalog dependency on Magento_Rating
  * Removed the Magento_Rating module, its logic moved to Magento_Review
  * Moved the View related components from Magento_Core to the Magento/View library
* Refactored the following modules to use Customer Service
  * Magento_Multishipping
  * Magento_Paypal
  * Magento_Log
  * Magento_RSS
  * Magento_Review
  * Magento_Wishlist
  * Magento_Weee
  * Magento_CatalogInventory
  * Magento_CatalogRule
  * Magento_SalesRule
* GitHub requests:
  * [#520] (#520) -- Fixed spelling in Magento\Payment\Model\Method\AbstractMethod
  * [#481] (#481) -- GD2 Adapter PHP memory_limit
  * [#516] (#516) -- Make Sure That save_before Event Is Dispatched
  * [#465] (#465) -- Absolute path is assembled incorrectly when merging js/css files
  * [#504] (#504) -- Renamed "contacts" module to "contact"
  * [#529] (#529) -- Fixed exception at admin dashboard
  * [#535] (#535) -- Fixed an issue during creating or editing product template
  * [#535] (#535) -- Fixed Typo in the module name
  * [#538] (#538) -- Fixed missing tax amount in the invoice
  * [#518] (#518) -- Change to Magento\Customer\Block\Widget\Dob new version
* Fixed bugs:
  * Fixed implementation issues with Cron task group threading
  * Fixed inability to place order during customer registration flow
  * Fixed an issue where after JS minification errors appeared when loading pages which contained minified JS
  * Fixed an issue where it was impossible for users with restricted permission to export certain entities
  * Fixed an issue where checkout was blocked by the "Please enter the State/Province" pop-up for customers that had saved addresses
  * Fixed an issue where a fatal error appeared when trying to check out the second time with OnePageCheckout
  * Fixed an issue where a fatal error appeared when trying to create an online invoice for an order placed with PayPal Express Checkout (Payment Action = Order)
  * Fixed an issue where the special price for a bundle product was calculated wrongly
  * Fixed an issue where a fatal error appeared when trying to create a shipment for an order if Magento was installed without the USPS module
  * Fixed an issue where the Lifetime Sales and Average Orders sections of the Admin Dashboard were missing
  * Fixed an issue where the active tab changed after changing the attribute set
  * Fixed an issue with incorrect order of product types in the Add Product menu in the backend
  * Fixed an issue with saving the tier price attribute
* JavaScript improvements:
  * Upgraded the frontend jQuery library to version 1.11
  * Upgraded the frontend jQuery UI library to version 1.10.4
  * Modified the loader widget to render content using handlebars
  * Added the 'use strict' mode to the accordion widget
  * Added the 'use strict' mode to the tab widget

verklov commented Apr 11, 2014

@rjocoleman, the team has processed your pull request. The code has been just released in dev73.

@verklov verklov closed this Apr 11, 2014

magento-team pushed a commit that referenced this pull request Mar 24, 2016

Merge pull request #481 from magento-extensibility/MAGETWO-50795-move…

[Extensibility] MAGETWO-50795: Move CatalogImportExportStaging to EE

mmansoorebay pushed a commit that referenced this pull request Oct 7, 2016

Merge pull request #481 from magento-jackalopes/MAGETWO-58017-github-…

Fixed issue:

- MAGETWO-58017 [GITHUB] Error creating configurable products in 2.1.1 #6424
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment