Skip to content

ini_parse_quantity() accepts invalid arguments as valid #11876

Closed

Description

@fisharebest

Description

While writing a polyfill for ini_parse_quantity() I found some invalid inputs that are wrongly accepted as valid.

See https://3v4l.org/ON6U1#v8.2.9 for a live demo

The following code:

<?php

var_dump(ini_parse_quantity('0x0x12'));

var_dump(ini_parse_quantity('0b+10'));
var_dump(ini_parse_quantity('0o+10'));
var_dump(ini_parse_quantity('0x+10'));

var_dump(ini_parse_quantity('0b 10'));
var_dump(ini_parse_quantity('0o 10'));
var_dump(ini_parse_quantity('0x 10'));

Resulted in this output:

int(18)
int(2)
int(8)
int(16)
int(2)
int(8)
int(16)

But I expected this output instead:

E_WARNING that the data is invalid - similar to other invalid arguments.

PHP Version

8.2.9

Operating System

No response

Activity

  1. Girgias commented on Aug 8, 2023

    @Girgias
    Member

    The "issue" is the call to ```ZEND_STRTOUL()``, this is part of the issue when introducing support for binary and octal prefixes in #9560

    The whitespace and prefix is stripped away before passing it to the Cstrtoul() (or whatever platform-dependent function) which will also strip +, -, whitespace and a hex prefix (as this is the only one supported).

    The warnings for:

    var_dump(zend_test_zend_ini_parse_quantity('0b0b10'));
    var_dump(zend_test_zend_ini_parse_quantity('0o0o10'));

    are also a tad weird.

    I don't really see a good way to fix this, but will try. @arnaud-lb what is your opinion on this? (well after you enjoyed your holiday)

  2. added a commit that references this issue on Aug 8, 2023
    2d4a42f
  3. added a commit that references this issue on Aug 30, 2023
    d229a48
  4. added 2 commits that reference this issue on Aug 30, 2023
    9b28e52
    a3725f1
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