Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:

I've got a friend who runs a website which has uploads via forms.

They've been experiencing the following error message:

cgi-lib.pl: reached end of input while seeking boundary of multipart. Format of CGI input is wrong
Now apart from the whole scary thing that they're using an application so old that it's using cgi-lib instead of CGI.pm, what does that mean and how can it be fixed/avoided?

I'm assuming that it's trying to upload a file but not getting an EOF that it recognises, or something?
--

“Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.”
M-J D

Replies are listed 'Best First'.
Re: cgi-lib.pl error messages
by chromatic (Archbishop) on Mar 14, 2003 at 23:54 UTC

    Multipart data has boundaries which separate various parts. What's happening is that it's running out of data in the request without seeing the ending boundary. That could be because of a broken web browser ignoring specifications, lost packets, elves, or an aborted upload.

    It also could be a bug in cgi-lib; standards have changed somewhat in the past several years.

    If it's a client side issue (and it's probably a client side issue), the best thing any server component can do is fail gracefully. You can't be sure you've received the whole file, so don't try to process it.

Re: cgi-lib.pl error messages
by tachyon (Chancellor) on Mar 15, 2003 at 02:49 UTC

    As already stated by chromatic multipart data has boundaries which delimit the data and the terminating boundary is not being found. Causes are crap browsers sending corrupt data, lost packets, aborted file uploads, or bugs in cgi-lib.pl. Both CGI.pm and CGI::Simple can do a drop in replacement for cgi-lib.pl which lets you rule out software - see the docs for details. This involves a simple 2 line change to the code in most cases. Otherwise you need to deal with it as it does happen for the above reasons. If you read the source of CGI::Simple you will see documented some of the hacks to fix the corrupt (non RFC standard) boundaries that various browsers send.

    If you want to see the actual boundary structure POST a multipart form to a simple CGI like this:

    #!/usr/bin/perl print "Content-type: text/plain\n\n"; print while read( STDIN, $_, 1024 );

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print