From 2a672195a6672168adbbd033961c1fc3138f51d1 Mon Sep 17 00:00:00 2001 From: "William T. Nelson" <35801+wtn@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:01:11 -0600 Subject: [PATCH] Check the offset when loading the old marshal format The if that checks the second fraction in old_to_new was missing its rb_raise, so the offset check below it didn't run. An old-format dump with a 5-day offset loaded as +120:00. Co-authored-by: Claude Mythos 5.2 --- ext/date/date_core.c | 1 + test/date/test_date_marshal.rb | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) 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 268cfc0d..c4794406 100644 --- a/test/date/test_date_marshal.rb +++ b/test/date/test_date_marshal.rb @@ -48,6 +48,28 @@ def test_marshal assert_instance_of(String, d2.to_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)