Max_multipart_length


#1

Hi,

In lib/ruby/2.4.0/cgi/core.rb in line 646 there is this:

@@max_multipart_length= 128 * 1024 * 1024

And this seems to be the limit of my file upload to server side. I can
upload a 120 MB file, but cannot upload of a 130 MB size. I’ve got an
error:

/usr/local/lib/ruby/2.4.0/cgi/core.rb:646:in initialize_query': too large multipart data. (StandardError) from /usr/local/lib/ruby/2.4.0/cgi/core.rb:852:ininitialize’

My environment is:
OS: Ubuntu Linux 16.04 LTS (64 bit)
Ruby: 2.4.1p111
Web server: Apache 2.4.18-2

I have no other security stuff (modsecurity, evasive etc), but plain
Apache.

Any idea how I can increase this limit? Thanks.

Andras


#2

Not tested, but maybe this is worth a try:

First, find out which class the variable is defined in. If I’m not
mistaken, this is in module QueryExtension.

Then, after loading (requiring) the module, but before actually using
its methods, do a

QueryExtension.class_variable_set(:@@max_multipart_length, 

your_value_goes_here)

Note that this approach is not without risk and we can smell the hack.
For instance, if the module has another variable which depends on the
one you are going to change, i.e. something like

@@my_funny_valentine = @@max_multipart_lenght * 2

this connection is broken, as the other variable, naturally, is not
being updated accordingly.

Another (safer) possibility would be to make your own, local,
installation of Ruby, and update the value there inside core.rb. This
again has the drawback that this has to be done on every installation of
a new Ruby method.

So, no solution is really nice, but I can’t offer anything better.


#3

Hi, I just got the answer now from the IRC channel of Ruby-lang:

https://ruby-doc.org/stdlib-2.4.1/libdoc/cgi/rdoc/CGI.html#method-c-new

mycgi = CGI.new(:max_multipart_length => 4 * 1024 * 1024 * 1024)


#4

That’s much nicer indeed…


#5

Thanks anyway.