Skip to content
This repository
Browse code

Ignore illegal seeks on body rewind. Catches CGI errors depending on …

…your httpd. Closes #10404 [Curtis Hawthorne]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8327 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit db885e81b9dc918a75bd66b1631a13e10447d0ff 1 parent 2766f76
Jeremy Kemper authored December 07, 2007
8  actionpack/lib/action_controller/request.rb
@@ -588,7 +588,13 @@ def read_multipart(body, boundary, content_length, env)
588 588
           end
589 589
           raise EOFError, "bad boundary end of body part" unless boundary_end=~/--/
590 590
 
591  
-          body.rewind if body.respond_to?(:rewind)
  591
+	  begin
  592
+            body.rewind if body.respond_to?(:rewind)
  593
+	  rescue Errno::ESPIPE
  594
+            # Handles exceptions raised by input streams that cannot be rewound
  595
+            # such as when using plain CGI under Apache
  596
+	  end
  597
+
592 598
           params
593 599
         end
594 600
     end
10  actionpack/test/controller/request_test.rb
@@ -736,6 +736,16 @@ def test_large_text_file
736 736
     assert ('a' * 20480) == file.read
737 737
   end
738 738
 
  739
+  uses_mocha "test_no_rewind_stream" do
  740
+    def test_no_rewind_stream
  741
+      # Ensures that parse_multipart_form_parameters works with streams that cannot be rewound
  742
+      file = File.open(File.join(FIXTURE_PATH, 'large_text_file'), 'rb')
  743
+      file.expects(:rewind).raises(Errno::ESPIPE)
  744
+      params = ActionController::AbstractRequest.parse_multipart_form_parameters(file, 'AaB03x', file.stat.size, {})
  745
+      assert_not_equal 0, file.pos  # file was not rewound after reading
  746
+    end
  747
+  end
  748
+
739 749
   def test_binary_file
740 750
     params = process('binary_file')
741 751
     assert_equal %w(file flowers foo), params.keys.sort

0 notes on commit db885e8

Please sign in to comment.
Something went wrong with that request. Please try again.