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

Fixes laminas/laminas-diactoros#10 #44

Merged
merged 2 commits into from
Jul 7, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/functions/create_uploaded_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function createUploadedFile(array $spec) : UploadedFile

return new UploadedFile(
$spec['tmp_name'],
$spec['size'],
$spec['error'],
intval($spec['size']),
intval($spec['error']),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think casting to would be a better alternative for this since there's no for the function call (we also don't need to perform any kind of base conversion).

Suggested change
intval($spec['size']),
intval($spec['error']),
(int) $spec['size'],
(int) $spec['error'],

I'm just afraid, though, that this hides the problem instead. The main question here is: how come these aren't integers?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting is fine. The underlying "problem" is that PHP returns the filesize as a string in the $_FILES global:

var_export($_FILES);

// array ( 'my_file' => array ( 'name' => 'myImage.png', 'type' => 'image/png', 'tmp_name' => '/tmp/phpr4VQcQ', 'error' => 0, 'size' => '50696', ), )

I now see that the error is actually an integer so only the size must be cast to integer. I'll change that.

Now, why the size is a string is not clear to me but it might have something to do with this bugfix from the past: https://bugs.php.net/bug.php?id=45124.

A 2GB file would be 2,147,483,648 bytes and max int (32 bit) would be 2,147,483,647. So it's possible they changed the size into a string because of that. This would be no problem with a 64 bit integer so I don't think it will be a problem just casting the string to an integer.

$spec['name'] ?? null,
$spec['type'] ?? null
);
Expand Down