Skip to content
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

Error in function setMax from Zend\Validator\File\Size for values greater than 2G #13

Closed
weierophinney opened this issue Dec 31, 2019 · 1 comment
Assignees
Labels
Won't Fix This will not be worked on

Comments

@weierophinney
Copy link
Member

If I'm using big values for the maximum limit, I have error on conversion in bytes.
In PHP, on a 32-bit system, the largest value that can be held in an INT is 2147483647. This is equal with 1.999999(and more digits) Gb.
I've tested the setMax with a greater value, like 8000M, but the tests can be made also with 2G.

The function setMax has a casting method to integer
$max = (int) $this->fromByteString($max);
This method will return a negative value because of the cast "(int)".

Example: setMax(7.81 GB) will have calculated max -204010947

The propose is to use "floor" casting like
$max = floor($this->fromByteString($max));

This bug is also presented in ZF3 package.

I'm giving you the example of usage of Size validator, from a getInputFilter() function. The value returned by the below call $this->getUploadMaxFilesize() is "8000M".

           $file = new FileInput('imagepath');
            $file->getValidatorChain()->attach(new UploadFile());
            if($this->getUploadMaxFilesize()) {
                $file->getValidatorChain()->attach(new Size(array('max' => $this->getUploadMaxFilesize())));
            }
            $file->getValidatorChain()->attach(new Extension(array(
                'extension' => $this->getUploadFileExtensions(),
                'case' => false,
                'messages' => array('fileExtensionFalse' => "Only " . implode("/", $this->getUploadFileExtensions()) . " extension are allowed. File '%value%' hasn't an allowed extension"),
            )));
            $file->getFilterChain()->attach(
                new RenameUpload([
                'target' => PUBLICDIR . $this->getUploadPath() . $this->getUploadFilePrefix(),
                'randomize' => true,
                'use_upload_name' => false,
                'use_upload_extension' => true,
                'overwrite' => false,
            ]));
            $inputFilter->add($file);

Originally posted by @BogMor at zendframework/zend-validator#199

@gsteel
Copy link
Member

gsteel commented Jul 16, 2024

Closed via #364

@gsteel gsteel closed this as not planned Won't fix, can't repro, duplicate, stale Jul 16, 2024
@gsteel gsteel added the Won't Fix This will not be worked on label Jul 16, 2024
@gsteel gsteel self-assigned this Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Won't Fix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants