Skip to content

Invalid values for upload_max_filesize cause undefined behavior. #14695

Open

Description

@kevinrsoursib

Description

If the value for upload_max_filesize is set to a non numeric value in the php.ini then it's not clear how the system is going to behave. For instance set
upload_max_filesize = bogus
in the php.ini file.

ini_get and phpinfo return the bogus string. As far as I can tell there is no limit enforced on uploads in this case but no warnings or errors are reported. This behavior is undocumented.

Other invalid values produce different results
upload_max_filesize = 1zz

Appears to set the limit to 1 byte. In general it appears that trailing input is ignored. This makes it very difficult to interpret the results of ini_get because that will return the value as it exists in the ini file but without knowing the exact rules it's impossible to convert this to the actual limit that PHP will enforce. In turn this makes it difficult to write diagnostic tools to try to detect why uploads are failing and suggest to users how to fix it.

Ideally to the extent that PHP is normalizing the value in the ini file, ini_get should return the normalized value that PHP is using. A completely invalid value should probably not be interpreted as "no limit whatsoever". That seems to invite an unfortunate typo turning into a potential DOS issue.

PHP Version

PHP 8.3.0

Operating System

Windows 10

Activity

  1. devnexen commented on Jun 30, 2024

    @devnexen
    Member

    Pb is, and you re right that s a bit of an issue for this kind of case, these ini entries are stored as string "as-is". Some work can be done before the zval get cast to a zend_string. Would need some thoughts for how to go about the value sanitisation policy.

  2. cmb69 commented on Jul 11, 2024

    @cmb69
    Member

    While I agree that there is room for improvement here, I wouldn't call the current behavior a bug (after all, these INI settings behave like this for many years). Maybe a respective feature request is more appropriate.

  3. bukka commented on Jul 21, 2024

    @bukka
    Member

    Agreed this is not a bug but more something that can be improved - it means feature...

  4. added a commit that references this issue on Jun 27, 2026
    998bce0
  5. LamentXU123 commented on Jun 27, 2026

    @LamentXU123
    Member

    This is accidentally closed through my commits. I am going to reopen it until the PR fixing this issue is merged. Sorry for the noise,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions