Ticket #130 (closed defect: fixed)

Opened 16 months ago

Last modified 3 months ago

[PATCH] Apache/CGI upload ESPIPE error

Reported by: jsheets Owned by: somebody
Priority: major Milestone: Camping 1.6
Component: camping.rb Version: 1.5
Keywords: apache upload cgi Cc:

Description

File uploads using Apache CGI fail with an ESPIPE error when calling seek() on the pipe. The stack against camping-unabridged.rb (r194):

(eval):419:in 'seek': Illegal seek (Errno::ESPIPE)
        from (eval):419:in 'initialize'
        from (eval):685:in 'run'

The workaround is to buffer the pipe with a StringIO.

       @in = r
       if %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)|n.match(e.CONTENT_TYPE)
+        @in = StringIO.new(r.read) if @in.stat.pipe?

Also, there appears to be a spurious debug statement that causes a malformed header error during uploads (deleted by the patch):

puts "=> fh[type] = #$1"

Change History

Changed 16 months ago by jsheets

  • summary changed from Apache/CGI upload ESPIPE error to [PATCH] Apache/CGI upload ESPIPE error

Changed 16 months ago by jsheets

Internal Server Error is preventing me from uploading the patch, so here it is:

Index: extlib/camping/lib/camping-unabridged.rb
===================================================================
--- extlib/camping/lib/camping-unabridged.rb	(revision 230)
+++ extlib/camping/lib/camping-unabridged.rb	(working copy)
@@ -390,6 +390,7 @@
       qs = C.qsp(e.QUERY_STRING)
       @in = r
       if %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)|n.match(e.CONTENT_TYPE)
+        @in = StringIO.new(r.read) if @in.stat.pipe?
         b = /(?:\r?\n|\A)#{Regexp::quote("--#$1")}(?:--)?\r$/
         until @in.eof?
           fh=H[]
@@ -399,7 +400,6 @@
             when /^Content-Disposition: form-data;/
               fh.u H[*$'.scan(/(?:\s(\w+)="([^"]+)")/).flatten]
             when /^Content-Type: (.+?)(\r$|\Z)/m
-              puts "=> fh[type] = #$1"
               fh[:type] = $1
             end
           end

Changed 16 months ago by jsheets

Oh. Huh. So just ignore the fact that I mistakenly took the above diff against a version of Camping checked into my app's svn repository. Still quacks like a duck!

Changed 11 months ago by zimbatm

Well, reading the whole file into memory is probably not a good idea. Couldn't we have a solution without seek ?

Changed 6 months ago by archengule

Would Camping::FastCGI::SeekStream? work for this?

Changed 3 months ago by judofyr

  • status changed from new to closed
  • resolution set to fixed

Now when we're using Rack, this should be fixed. If not, it's not our fault, but Rack's.

Note: See TracTickets for help on using tickets.