Navigation Menu

Skip to content

Commit

Permalink
Ignore illegal seeks on body rewind. Catches CGI errors depending on …
Browse files Browse the repository at this point in the history
…your httpd. Closes rails#10404 [Curtis Hawthorne]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8327 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Dec 7, 2007
1 parent 2766f76 commit db885e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion actionpack/lib/action_controller/request.rb
Expand Up @@ -588,7 +588,13 @@ def read_multipart(body, boundary, content_length, env)
end end
raise EOFError, "bad boundary end of body part" unless boundary_end=~/--/ raise EOFError, "bad boundary end of body part" unless boundary_end=~/--/


body.rewind if body.respond_to?(:rewind) begin
body.rewind if body.respond_to?(:rewind)
rescue Errno::ESPIPE
# Handles exceptions raised by input streams that cannot be rewound
# such as when using plain CGI under Apache
end

params params
end end
end end
Expand Down
10 changes: 10 additions & 0 deletions actionpack/test/controller/request_test.rb
Expand Up @@ -736,6 +736,16 @@ def test_large_text_file
assert ('a' * 20480) == file.read assert ('a' * 20480) == file.read
end end


uses_mocha "test_no_rewind_stream" do
def test_no_rewind_stream
# Ensures that parse_multipart_form_parameters works with streams that cannot be rewound
file = File.open(File.join(FIXTURE_PATH, 'large_text_file'), 'rb')
file.expects(:rewind).raises(Errno::ESPIPE)
params = ActionController::AbstractRequest.parse_multipart_form_parameters(file, 'AaB03x', file.stat.size, {})
assert_not_equal 0, file.pos # file was not rewound after reading
end
end

def test_binary_file def test_binary_file
params = process('binary_file') params = process('binary_file')
assert_equal %w(file flowers foo), params.keys.sort assert_equal %w(file flowers foo), params.keys.sort
Expand Down

0 comments on commit db885e8

Please sign in to comment.