Commit 122376df authored by Justin Blanchard's avatar Justin Blanchard Committed by Serhiy Storchaka

bpo-37372: Fix error unpickling datetime.time objects from Python 2 with seconds>=24. (GH-14307)

parent e64f948e
...@@ -3324,13 +3324,22 @@ class TestTime(HarmlessMixedComparison, unittest.TestCase): ...@@ -3324,13 +3324,22 @@ class TestTime(HarmlessMixedComparison, unittest.TestCase):
def test_compat_unpickle(self): def test_compat_unpickle(self):
tests = [ tests = [
b"cdatetime\ntime\n(S'\\x14;\\x10\\x00\\x10\\x00'\ntR.", (b"cdatetime\ntime\n(S'\\x14;\\x10\\x00\\x10\\x00'\ntR.",
b'cdatetime\ntime\n(U\x06\x14;\x10\x00\x10\x00tR.', (20, 59, 16, 64**2)),
b'\x80\x02cdatetime\ntime\nU\x06\x14;\x10\x00\x10\x00\x85R.', (b'cdatetime\ntime\n(U\x06\x14;\x10\x00\x10\x00tR.',
(20, 59, 16, 64**2)),
(b'\x80\x02cdatetime\ntime\nU\x06\x14;\x10\x00\x10\x00\x85R.',
(20, 59, 16, 64**2)),
(b"cdatetime\ntime\n(S'\\x14;\\x19\\x00\\x10\\x00'\ntR.",
(20, 59, 25, 64**2)),
(b'cdatetime\ntime\n(U\x06\x14;\x19\x00\x10\x00tR.',
(20, 59, 25, 64**2)),
(b'\x80\x02cdatetime\ntime\nU\x06\x14;\x19\x00\x10\x00\x85R.',
(20, 59, 25, 64**2)),
] ]
args = 20, 59, 16, 64**2 for i, (data, args) in enumerate(tests):
with self.subTest(i=i):
expected = self.theclass(*args) expected = self.theclass(*args)
for data in tests:
for loads in pickle_loads: for loads in pickle_loads:
derived = loads(data, encoding='latin1') derived = loads(data, encoding='latin1')
self.assertEqual(derived, expected) self.assertEqual(derived, expected)
......
...@@ -162,6 +162,7 @@ Roy Bixler ...@@ -162,6 +162,7 @@ Roy Bixler
Daniel Black Daniel Black
Jonathan Black Jonathan Black
Renaud Blanch Renaud Blanch
Justin Blanchard
Mike Bland Mike Bland
Martin Bless Martin Bless
Pablo Bleyer Pablo Bleyer
......
Fix error unpickling datetime.time objects from Python 2 with seconds>=24.
Patch by Justin Blanchard.
...@@ -4078,7 +4078,7 @@ time_new(PyTypeObject *type, PyObject *args, PyObject *kw) ...@@ -4078,7 +4078,7 @@ time_new(PyTypeObject *type, PyObject *args, PyObject *kw)
return NULL; return NULL;
} }
if (PyUnicode_GET_LENGTH(state) == _PyDateTime_TIME_DATASIZE && if (PyUnicode_GET_LENGTH(state) == _PyDateTime_TIME_DATASIZE &&
(0x7F & PyUnicode_READ_CHAR(state, 2)) < 24) (0x7F & PyUnicode_READ_CHAR(state, 0)) < 24)
{ {
state = PyUnicode_AsLatin1String(state); state = PyUnicode_AsLatin1String(state);
if (state == NULL) { if (state == NULL) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment