Error in function setMax from Zend\Validator\File\Size for values greater than 2G
Opened this issue · 1 comments
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);
This repository has been closed and moved to laminas/laminas-validator; a new issue has been opened at laminas/laminas-validator#13.