diff --git a/ext/date/date_core.c b/ext/date/date_core.c index b3040171..206732e7 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -3369,6 +3369,7 @@ old_to_new(VALUE ajd, VALUE of, VALUE sg, if (f_lt_p(*rsf, INT2FIX(0)) || f_ge_p(*rsf, INT2FIX(SECOND_IN_NANOSECONDS))) + rb_raise(eDateError, "invalid second fraction"); if (*rof < -DAY_IN_SECONDS || *rof > DAY_IN_SECONDS) { *rof = 0; diff --git a/test/date/test_date_marshal.rb b/test/date/test_date_marshal.rb index 8b1284e1..9990e3d2 100644 --- a/test/date/test_date_marshal.rb +++ b/test/date/test_date_marshal.rb @@ -57,6 +57,28 @@ def test_marshal_nth assert_equal(Date.new(-123456,7,8), Marshal.load(s)) end + def test_marshal_load_old_format_offset + d = DateTime.allocate + d.marshal_load([Rational(0), Rational(1, 24), Date::ITALY]) + assert_equal(Rational(1, 24), d.offset) + + d = DateTime.allocate + d.marshal_load([Rational(0), 1, Date::ITALY]) + assert_equal(1, d.offset) + + d = DateTime.allocate + assert_warning(/invalid offset/) do + d.marshal_load([Rational(0), 5, Date::ITALY]) + end + assert_equal(0, d.offset) + + d = DateTime.allocate + assert_warning(/invalid offset/) do + d.marshal_load([Rational(0), -5, Date::ITALY]) + end + assert_equal(0, d.offset) + end + def test_memsize require 'objspace' t = DateTime.new(2018, 11, 13)