-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
Add internal IniUtil helper class to convert ini size settings to bytes #276
Conversation
Since this function is going to be used for parsing user input, there should probably at least some basic guards against invalid input. Maybe we should throw a |
@jsor good point, added tests for that 👍 |
src/Util.php
Outdated
$strippedSize = substr($size, 0, -1); | ||
|
||
if (!is_numeric($strippedSize)) { | ||
throw new \InvalidArgumentException('"' . $strippedSize . '" is not a valid ini size'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exception message should probably use the passed $size
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, that fails for single-digits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers, fixed that 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And also addressed the single digit issue 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Motivation for this PR is a bit unclear on its own, does it make sense to update the related classes as part of this PR?
src/Util.php
Outdated
{ | ||
if (is_numeric($size) && $size <= 0) { | ||
throw new \InvalidArgumentException('Expect "' . $size . '" to be higher isn\'t zero or lower'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the motivation for this check? memory_limit
can be set to -1
to allow unlimited memory (http://php.net/manual/en/ini.core.php#ini.memory-limit), while other ini settings do not allow this.
Should this be covered by this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, motivation for it was to catch invalid values but it escaped my mind that -1 is a valid value
src/Util.php
Outdated
/** | ||
* @internal | ||
*/ | ||
final class Util |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big fan of a "utility" class, but given this is @internal
only, I won't block this and would rather clean this up in a follow-up PR 👍
Does it make sense to move this to Io
namespace so this is less prominent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neither am I, another option would be to create a functions file. Moved it under Io
@clue The initial idea was to add this method first and then file follow up PR for updating uses. But as suggested I've updated the related classes within this PR now 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick update! Can you squash this to a reasonable number of commits, changes LGTM otherwise 👍
a87e3eb
to
2d951f0
Compare
Cheers, rebased and squashed into one commit 👍 . Ping @jsor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, overlooked the fact that this is supposed to resolve #275, added some minor remarks below 👍
src/Io/MultipartParser.php
Outdated
@@ -82,7 +82,7 @@ public function __construct($uploadMaxFilesize = null, $maxFileUploads = null) | |||
$this->maxInputNestingLevel = (int)$var; | |||
} | |||
|
|||
$this->uploadMaxFilesize = $uploadMaxFilesize === null ? $this->iniUploadMaxFilesize() : (int)$uploadMaxFilesize; | |||
$this->uploadMaxFilesize = $uploadMaxFilesize === null ? Util::iniSizeToBytes(ini_get('upload_max_filesize')) : Util::iniSizeToBytes($uploadMaxFilesize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified by moving this out of the ternary. Also, needs tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated a test to test this change
@@ -21,7 +22,7 @@ | |||
public function __construct($sizeLimit = null) | |||
{ | |||
if ($sizeLimit === null) { | |||
$sizeLimit = $this->iniMaxPostSize(); | |||
$sizeLimit = Util::iniSizeToBytes(ini_get('post_max_size')); | |||
} | |||
|
|||
$this->sizeLimit = $sizeLimit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that explicitly giving a size here does not allow size suffixes. Also needs tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah seems that slipped through, fixed it here 👍
@clue Updated the PR, let me know if this is good and I'll squash again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick update and sorry for the confusion! Can you squash this, otherwise LGTM?
Renamed |
133d629
to
d6592cc
Compare
d6592cc
to
1f54423
Compare
1f54423
to
1439879
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes LGTM, thanks for the keeping up with this! 👍
Created Util::iniSizeToBytes() helper so we don't have to copy the same internal method everywhere. A follow up PR can take care of #275. This will also be used in #271.