kraih/mojo — pull request #445 by augensalat (2013-01-16 14:45:47+00:00)
Title: Issue with huge file uploads on 32-bit Perl

I have to depoy a Mojolicious application on a Perl 5.10.1 w/ 32 bit on an Open Solaris system.
That application offers a file upload.
By trying to upload a file > 2G (and smaller than 4G) with multipart/form-data, the application tries to load everything into RAM - **without considerung $MOJO_MAX_MESSAGE_SIZE**.
The reason seems to be an overflow of a signed 32-bit decimal in substr(). A simple test:

[host ~]# perl -wE 'my $s = "abc"; say length(substr $s, 0, 2_200_000_000)'
0

On a 64-bit system the result is '3' of course.

Also interesting is the double-overflow btw:

[host ~]# perl -wE 'my $s = "abc"; say length(substr $s, 0, 4_400_000_000)'
2

The additional tests in t/mojo/content.t are failing without the changes in lib/Mojo/Content.pm .