php-src icon indicating copy to clipboard operation
php-src copied to clipboard

PHP does not report invalid values for file sizes and interpret them incorrectly

Open salarmehr opened this issue 4 years ago • 6 comments

Description

There is no error message given if you accidentally use KB, MB or GB instead of K, M or G. and they will be evaluated to some other values. phpinfo() and ini_get() will report what you have written e.g. 1GB , so it will not be clear that there is anything wrong with your setting even though there is.

Expected behaviour: Show a notice/warning and revert to the default value.

Links: https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes

PHP Version

7., 8.

Operating System

No response

salarmehr avatar Dec 31 '21 06:12 salarmehr

The behavior is clearly documented:

The available options are K (for Kilobytes), M (for Megabytes) and G (for Gigabytes), and are all case-insensitive. Anything else assumes bytes.

That said, I don't know of a reason why zend_atol (I assume that's where the INI parser gets this from) couldn't also support GB/MB/KB, as I doubt anyone is currently using it and expecting to get byte values. On a related note, might be a good time to add support for T/TB.

If not then this is a doc issue: to explicitly call out the *Bs as not being supported.

damianwadley avatar Dec 31 '21 07:12 damianwadley

@salarmehr yes, it assumes it byte but it does not show the "assumed" value on the PHP info page. It's better to not assume a wrong value and show some error message.

salarmehr avatar Dec 31 '21 08:12 salarmehr

Somewhat related: zend_atol() parses 128ksomething as 128g.

cmb69 avatar Dec 31 '21 11:12 cmb69

This would be addressed by PR #7788 in a backward compatible way.

cmb69 avatar Jan 10 '22 18:01 cmb69

Related to #7951

Girgias avatar Jun 09 '22 12:06 Girgias

Fixed in https://github.com/php/php-src/pull/7951 (PHP >= 8.2)

arnaud-lb avatar Jul 08 '22 13:07 arnaud-lb