-
Notifications
You must be signed in to change notification settings - Fork 822
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
Fix clobbering of the upload size validation #10059
Conversation
Fixes |
It's a PR for #10058, 10059 is the PR itself. I don't think we can remove that block just like that, it removes setting the max size completely from the validator. It will need adjusting the logic, but not removing it. |
@michalkleiner It gets set when the validation is first actually called. If nothing has been defined in the config it falls back to original behaviour. https://github.com/silverstripe/silverstripe-assets/blob/1/src/Upload_Validator.php#L117 Edit; |
Hmm, interesting the tests are passing, so it's either not being covered by tests properly or the code really wasn't needed. |
Adding a test specifically for this config scenario would be great, that way we'd be 100% sure. |
@michalkleiner tests added. The second test fails without my fix. |
@michalkleiner All good? |
Looks ok to me, though I can't approve it yet, so we need to wait for another core committer to give it a tick. |
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.
Shouldn't it be something like this in order to fix the inverse problem? i.e. your config value is greater than the ini values?
$maxConfig = <get a config value if specified>
$min = $maxConfig ? min($maxUpload, $maxPost, $maxConfig) : min($maxUpload, $maxPost);
$this->getValidator()->setAllowedMaxFileSize($min);
If your config sets a max file size of say 5000 MB, which is above what's defined in php ini, then wouldn't php will block you from uploading it?
@emteknetnz Currently if you do You'll see my commits removes that code which means it flows through to the code that does check the config and lets it work properly. |
This doesn't seem correct, I just tried testing this PR I set my config to:
And uploading a 700kb image, validation message was correct saying However when I changed my php.ini to |
@emteknetnz The bug your running into looks like an existing bug in core which is now being exposed in https://github.com/silverstripe/silverstripe-assets/blob/1/src/Upload_Validator.php#L117 - as we can see this existing code isn't checked if the config value will exceed PHP defaults. Would you like me to fix that as part of this PR, or keep the PR specific? |
Seems like it should be fixed at the same time if you're able to do that. Seems logical that the validator should set the max size to be the minimum of (config, upload_max_filesize, post_max_size) |
@emteknetnz The fix I am going to make will be in the https://github.com/silverstripe/silverstripe-assets package, since that is where the Upload_Validator is. |
@nfauchelle 1.9 please and thanks |
PR added at silverstripe/silverstripe-assets#469 |
So this PR now fixes two issues. The first being my original upload size validation not working. I believe we're all good to go here. |
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.
I've left some comments on the corresponding assets pr - silverstripe/silverstripe-assets#469 (review)
When the validation is set here like this, it overrides validation which has already been setup with a simple '*' rule for the size based on PHP. If you've defined in the sites yml config something like SilverStripe\Assets\Upload_Validator: default_max_file_size: '[image]': '2m' '*' : '1m' then it will not be respected. If you review SilverStripe\Assets\Upload_Validator and check the getAllowedMaxFileSize method, you'll see the sizing will be populated (if it hasn't been done before). You can see it fail by; - Setup a new SilverStripe site. - Set your PHP to allow max post / max upload size of 10mb. - Add the above config to your sites yml file and flush. - In the CMS you'll be able to upload a 5MB file, when you shouldn't.
Couple of tests which prove a fix so the FileField and others will use the default_max_file_size setting
This is what happens when you refactor in the github window. Fix the variable names. This will get squashed once merged.
…rsion Remove extra white space to appease the CS. Use the non deprecated method for memstring2bytes
White space fixes for the phpcs
… number is passed in
I've rebased and retargetted to Also bumped the assets constraint as per silverstripe/silverstripe-assets#469 (review) but otherwise left as-is. |
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.
Have tested this and associated PRs locally, they work good
Issue #10058
When the validation is set here like this, it overrides validation which has already been setup with a simple '*' rule for the size based on PHP.
If you've defined in the sites yml config something like
then it will not be respected.
If you review SilverStripe\Assets\Upload_Validator and check the getAllowedMaxFileSize method, you'll see the sizing will be populated (if it hasn't been done before).
You can see it fail by;