New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getRealSize should expect also literals, not only integers #14307

Open
iamntz opened this Issue May 19, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@iamntz

iamntz commented May 19, 2018

 if ($postsize = ini_get('post_max_size')) {
            $this->set(
                'max_upload_size',
                min(Core::getRealSize($filesize), Core::getRealSize($postsize))
            );
        } else {
            $this->set('max_upload_size', Core::getRealSize($filesize));
        }

This block throw an error, because getRealSize is failing if the php.ini will have shorthands (e.g. 1G).

The default php.ini is post_max_size=8M

Server configuration

Operating system:
Windows 10

Web server:

Database:

mysql --version
mysql  Ver 15.1 Distrib 10.2.14-MariaDB, for Win64 (AMD64)

PHP version:

PHP 7.2.5 (cli) (built: Apr 25 2018 02:39:21) ( ZTS MSVC15 (Visual C++ 2017) x86 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans

phpMyAdmin version:
HEAD

@nulll-pointer

This comment has been minimized.

Contributor

nulll-pointer commented May 20, 2018

This block throw an error, because getRealSize expects strictly an integer, but will fail if the php.ini will have shorthands (e.g. 1G).

I don't think it's true, Having a quick look at the function definition, I think it accepts the shorthands.
If the size is not in an acceptable shorthand format, it typecasts it into an integer.

@iamntz

This comment has been minimized.

iamntz commented May 21, 2018

Yeah, so it seems I'm a bit dumb about this new return type declaration thingy, so I misunderstood some stuff. That : int at the end of the declaration means that the method should return an integer, and not that is expecting an integer (dooh).


I'm not sure if this is specific on Windows platform, on my machine or PHP in general, but stuff looks like this. I did a bit of fidding on Core class, on method getRealSize

gettype($matches[1]) => string (value is 2)
gettype($binaryprefixes[$matches[2]]) => integer
gettype($matches[1] * $binaryprefixes[$matches[2]])  => double (value is 2147483648)

Now, this gets really interesting:

    if (preg_match('/^([0-9]+)([KMGT])/i', $size, $matches)) {
        return (int) ($matches[1] * $binaryprefixes[$matches[2]]);
    }

If I'm doing this, the return value is -2147483648. Yup, negative.

Can anyone explain why this is happen? I mean the confusion is double:

  • why multiplying an integer with a string results in an double?
  • why casting to int converts to negative?
@nulll-pointer

This comment has been minimized.

Contributor

nulll-pointer commented May 21, 2018

It's good that you mentioned that you are using windows, as stated here, the size of int in windows below php 7 is 32 bits, maybe that's why it overflows.

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