Index: cgi.rb =================================================================== --- cgi.rb (revision 16234) +++ cgi.rb (working copy) @@ -1020,16 +1020,18 @@ buf[0 ... (buf.size - (EOL + boundary + EOL).size)] = "" end - c = if bufsize < content_length - stdinput.read(bufsize) - else - stdinput.read(content_length) - end - if c.nil? || c.empty? - raise EOFError, "bad content body" - end - buf.concat(c) - content_length -= c.size + if content_length > 0 + c = if bufsize < content_length + stdinput.read(bufsize) + else + stdinput.read(content_length) + end + if c.nil? || c.empty? + raise EOFError, "bad content body" + end + buf.concat(c) + content_length -= c.size + end end buf = buf.sub(/\A((?:.|\n)*?)(?:[\r\n]{1,2})?#{quoted_boundary}([\r\n]{1,2}|--)/n) do @@ -1068,8 +1070,8 @@ else params[name] = [body] end - break if buf.size == 0 break if content_length == -1 + break if buf.size == 0 && content_length == 0 end raise EOFError, "bad boundary end of body part" unless boundary_end=~/--/