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

Fixes laminas/laminas-diactoros#10 #44

merged 2 commits into from
Jul 7, 2020

Conversation

halfpastfouram
Copy link

@halfpastfouram halfpastfouram commented Jul 3, 2020

Signed-off-by: halfpastfouram

Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC no
QA no

Description

Really simple fix for #10 with no BC breaks or anything. See #10 (comment).

Signed-off-by: halfpastfouram <[email protected]>
Comment on lines 35 to 36
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.

Signed-off-by: halfpastfouram <[email protected]>
weierophinney added a commit that referenced this pull request Jul 7, 2020
Signed-off-by: Matthew Weier O'Phinney <[email protected]>
@weierophinney weierophinney merged commit 95e2199 into laminas:master Jul 7, 2020
weierophinney added a commit that referenced this pull request Jul 7, 2020
Forward port #44

Conflicts:
	CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants