Permalink
Browse files

Fix stack overflow (RegexpError) triggered by large emails with an en…

…velope
  • Loading branch information...
1 parent f19ffd4 commit 702b306886bae732f2c6c15860320e20143b0059 @bpot bpot committed Jun 5, 2012
Showing with 11 additions and 3 deletions.
  1. +3 −2 lib/mail/message.rb
  2. +8 −1 spec/mail/message_spec.rb
View
@@ -1914,9 +1914,10 @@ def process_body_raw
end
def set_envelope_header
- if match_data = raw_source.to_s.match(/\AFrom\s(#{TEXT}+)#{CRLF}(.*)/m)
+ raw_string = raw_source.to_s
+ if match_data = raw_source.to_s.match(/\AFrom\s(#{TEXT}+)#{CRLF}/m)
set_envelope(match_data[1])
- self.raw_source = match_data[2]
+ self.raw_source = raw_string.sub(match_data[1], "")
end
end
@@ -94,6 +94,14 @@ def basic_email
errors.should be_false
end
+ it "should be able to parse a large email without raising an exception" do
+ m = Mail.new
+ m.add_file(:filename => "attachment.data", :content => "a" * (8 * 1024 * 1024))
+ raw_email = "From jamis_buck@byu.edu Mon May 2 16:07:05 2005\r\n#{m.to_s}"
+
+ doing { Mail::Message.new(raw_email) }.should_not raise_error
+ end
+
it "should not raise a warning on having non US-ASCII characters in the header (should just handle it)" do
STDERR.should_not_receive(:puts)
Mail::Message.new(File.read(fixture('emails', 'plain_emails', 'raw_email_string_in_date_field.eml')))
@@ -217,7 +225,6 @@ def basic_email
m.from.should eq ["News@InsideApple.Apple.com"]
m.should be_multipart
end
-
end
describe "accepting a plain text string email" do

0 comments on commit 702b306

Please sign in to comment.