diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-17 13:20:50 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-17 13:20:50 +0000 |
commit | 5685abe6c3b028bb72647305987cdea694cd78e2 (patch) | |
tree | 71cf9a064f4f7a32b73367a45c8abf20893ce6e5 /test | |
parent | 61313ade46f71b783336b64049ad11459a208061 (diff) | |
download | ruby-5685abe6c3b028bb72647305987cdea694cd78e2.tar.gz |
time.c: ignore invalid data
* time.c (time_mload): ignore invalid offset and zone.
[ruby-core:56648] [Bug #8795]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_time.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index 2a56836cce..e57601917d 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -312,6 +312,43 @@ class TestTime < Test::Unit::TestCase "[ruby-dev:44827] [Bug #5586]") end + def in_timezone(zone) + orig_zone = ENV['TZ'] + + ENV['TZ'] = 'UTC' + yield + ensure + ENV['TZ'] = orig_zone + end + + Bug8795 = '[ruby-core:56648] [Bug #8795]' + + def test_marshal_broken_offset + data = "\x04\bIu:\tTime\r\xEFF\x1C\x80\x00\x00\x00\x00\x06:\voffset" + t1 = t2 = nil + in_timezone('UTC') do + assert_nothing_raised(TypeError, ArgumentError, Bug8795) do + t1 = Marshal.load(data + "T") + t2 = Marshal.load(data + "\"\x0ebadoffset") + end + assert_equal(0, t1.utc_offset) + assert_equal(0, t2.utc_offset) + end + end + + def test_marshal_broken_zone + data = "\x04\bIu:\tTime\r\xEFF\x1C\x80\x00\x00\x00\x00\x06:\tzone" + t1 = t2 = nil + in_timezone('UTC') do + assert_nothing_raised(TypeError, ArgumentError, Bug8795) do + t1 = Marshal.load(data + "T") + t2 = Marshal.load(data + "\"\b\0\0\0") + end + assert_equal('UTC', t1.zone) + assert_equal('UTC', t2.zone) + end + end + def test_at3 t2000 = get_t2000 assert_equal(t2000, Time.at(t2000)) |