POST Content-Length exeeds the limit in Unknown on line 0

New topics about Symfony 2 should go here

Moderators: tiagojsag, dcobalt

POST Content-Length exeeds the limit in Unknown on line 0

Postby msalsas » Fri Jul 05, 2013 5:45 pm

Hi! I'm uploading an image from the client that has to be smaller than 900KB.
I avoid larger files using javascript, but I want to do it in the server too.
The form action is a controller where I've tried to do the next:

Code: Select all
//src/XXX/HomeBundle/Controller/HomeController.php

public function submitAction()
   {
      exit();
//...
        }


And I'm getting a warning and an error:

Warning: POST Content-Length of 799518963 bytes exceeds the limit of 10485760 bytes in Unknown on line 0

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 265289728 bytes) in /home/manolo/MiServer/itransformer/app/cache/dev/classes.php on line 3419


So if I can't catch the error in the controller, where can I do it?

I've tried allowing more memory to php.ini, and more length to post_max_size and upload_max_filesize. Finally I've got no errors by changing post_max_size and upload_max_filesize to 2G. I'm not sure if it's a good idea, because I don't want to let upload more than 900KB files.
Is there any way to catch the message before the warnig and error?

Thanks
-----------------------------------------------------
| http://msalsas.com | http://itransformer.es |
-----------------------------------------------------
msalsas
Member
 
Posts: 53
Joined: Fri Jun 21, 2013 2:28 pm

Re: POST Content-Length exeeds the limit in Unknown on line

Postby tiagojsag » Sat Jul 06, 2013 12:24 am

Hi,

You controller calls exit()? what exactly are you trying to achieve with that?
Unless you have a REAAAALLY good reason for it, nothing coming from your web server should need 256MB of memory like your request seems to do. My guess is that, between your weird code and weird errors, you are doing something really weird, that's creating a cycle that's exceeding PHP's memory limit.

http://symfony.com/doc/current/referenc ... /File.html
Symfony has built in constraints to limit file size. Read the above link, plus the book's section on forms and validation, and you should have enough to achieve what you want

cheers
Tiago Garcia
@tiagojsag

Core Web Developer @ Shopware
http://www.shopware.de
User avatar
tiagojsag
Faithful Member
 
Posts: 885
Joined: Wed Aug 10, 2011 4:58 pm

Re: POST Content-Length exeeds the limit in Unknown on line

Postby msalsas » Sun Jul 07, 2013 10:56 am

I had the memory limit to 256M because I was proving different values. But finally I found out that with 128M in memory_limit and 2G in post_max_size and upload_max_filesize it works with any file size.

The reason for putting exit() in the first line of the controller was to show that the error was not in the controller.

I had not seen the symfony's file validator, but now I have my application almost finished and don't want to change everything (thanks for the reference anyway :D~:-D~:grin: ).
I've done my validation by $_FILES['file']['size'], $_FILES['file']['error'] and $_FILES['file']['name'], and I've got all I wish.
Anyway, as exit() shows, the error comes before the validation, and it disappears when post_max_size and upload_max_filesize are putted to 2G.
But, could it be a vulnerability of the application? I'd rather not to do this, but I've not found other solution...
-----------------------------------------------------
| http://msalsas.com | http://itransformer.es |
-----------------------------------------------------
msalsas
Member
 
Posts: 53
Joined: Fri Jun 21, 2013 2:28 pm

Re: POST Content-Length exeeds the limit in Unknown on line

Postby tiagojsag » Sun Jul 07, 2013 1:12 pm

Well, I've done file uploads on multiple ocasions and I never had such problem. I strongly advice you to check your code, including any JS magic you might be trying to do. If you still can't find it, try it on a clean Symfony installation and if it's still there, report it on Symfony's github, including the mentioned sandbox, if possible.

cheers
Tiago Garcia
@tiagojsag

Core Web Developer @ Shopware
http://www.shopware.de
User avatar
tiagojsag
Faithful Member
 
Posts: 885
Joined: Wed Aug 10, 2011 4:58 pm

Re: POST Content-Length exeeds the limit in Unknown on line

Postby msalsas » Mon Jul 08, 2013 12:26 pm

I've seen that the key is post_max_size. When I put it to 2G and upload_max_filesize to 2M it works.
It's not any js script because I've tried disabling javascript.
When you say a clean Symfony installation, do you mean remove vendors/Symfony and...

Code: Select all
sudo php composer.phar update symfony/symfony


...? well, it makes no changes.

I've also tried to put exit(); in the first line of the app_dev.php file, but the warning persist.

This is my form:

Code: Select all
<form id="fileupload" class="form" action="{{ path('msd_home_submit') }}" method="post" enctype="multipart/form-data" >         
         <input type="hidden" name="MAX_FILE_SIZE" value="900000">
         <input class="in_file" type="file" name="userfile">
         <input class="enviar" type="submit" value="Aceptar">
         </form>


And these are the relevant values in php.ini:

Code: Select all
post_max_size = 10M
upload_max_filesize = 2M
memory_limit = 128M


How I've saied before, if post_max_size = 2G it works.

Any idea of post_max_size error?
-----------------------------------------------------
| http://msalsas.com | http://itransformer.es |
-----------------------------------------------------
msalsas
Member
 
Posts: 53
Joined: Fri Jun 21, 2013 2:28 pm

Re: POST Content-Length exeeds the limit in Unknown on line

Postby msalsas » Mon Jul 08, 2013 12:28 pm

Shit! I've found out the problem. It's a novel error. I had put method="post" in the form. Leaving this, it works perfectly.
-----------------------------------------------------
| http://msalsas.com | http://itransformer.es |
-----------------------------------------------------
msalsas
Member
 
Posts: 53
Joined: Fri Jun 21, 2013 2:28 pm

Re: POST Content-Length exeeds the limit in Unknown on line

Postby msalsas » Mon Jul 08, 2013 12:30 pm

Or maybe not really novel. Why does it works if it uses get method?
-----------------------------------------------------
| http://msalsas.com | http://itransformer.es |
-----------------------------------------------------
msalsas
Member
 
Posts: 53
Joined: Fri Jun 21, 2013 2:28 pm

Re: POST Content-Length exeeds the limit in Unknown on line

Postby msalsas » Mon Jul 08, 2013 12:45 pm

x(~:dead: Ups! Sorry, I've writted too fast... It does not upload with get method.
-----------------------------------------------------
| http://msalsas.com | http://itransformer.es |
-----------------------------------------------------
msalsas
Member
 
Posts: 53
Joined: Fri Jun 21, 2013 2:28 pm

Re: POST Content-Length exeeds the limit in Unknown on line

Postby tiagojsag » Mon Jul 08, 2013 1:30 pm

Ok. glad you found your problem.
Also, next time, please try to keep the vocabulary a little more appropriate ;)

cheers
Tiago Garcia
@tiagojsag

Core Web Developer @ Shopware
http://www.shopware.de
User avatar
tiagojsag
Faithful Member
 
Posts: 885
Joined: Wed Aug 10, 2011 4:58 pm

Re: POST Content-Length exeeds the limit in Unknown on line

Postby msalsas » Mon Jul 08, 2013 1:40 pm

Ok. I'll be more careful next time. But the problem persist. :(~:-(~:sad:
I imagined that the problem was in the form, but I think it must be post method and multipart/form-data enctype, so isn't the problem here...
-----------------------------------------------------
| http://msalsas.com | http://itransformer.es |
-----------------------------------------------------
msalsas
Member
 
Posts: 53
Joined: Fri Jun 21, 2013 2:28 pm

Re: POST Content-Length exeeds the limit in Unknown on line

Postby msalsas » Mon Jul 08, 2013 4:58 pm

Well, I think it's a problem with Apache configuration. Adding this to httpd.conf ...:

Code: Select all
<Files *.php>
  SetOutputFilter PHP
  SetInputFilter PHP
  LimitRequestBody 5242880
</Files>


get a "connection resset error" instead of the error commented before. :?~:-?~:???:
-----------------------------------------------------
| http://msalsas.com | http://itransformer.es |
-----------------------------------------------------
msalsas
Member
 
Posts: 53
Joined: Fri Jun 21, 2013 2:28 pm


Return to General Symfony 2 discussion

Who is online

Users browsing this forum: Bing [Bot], Google Feedfetcher and 9 guests