Skip to content

Commit db885e8

Browse files
committed
Ignore illegal seeks on body rewind. Catches CGI errors depending on your httpd. Closes rails#10404 [Curtis Hawthorne]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8327 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
1 parent 2766f76 commit db885e8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

actionpack/lib/action_controller/request.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,13 @@ def read_multipart(body, boundary, content_length, env)
588588
end
589589
raise EOFError, "bad boundary end of body part" unless boundary_end=~/--/
590590

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+
592598
params
593599
end
594600
end

actionpack/test/controller/request_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,16 @@ def test_large_text_file
736736
assert ('a' * 20480) == file.read
737737
end
738738

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+
739749
def test_binary_file
740750
params = process('binary_file')
741751
assert_equal %w(file flowers foo), params.keys.sort

0 commit comments

Comments
 (0)