php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch dateinterval-unserialize for Date/time related Bug #70153

Patch version 2015-07-27 14:27 UTC

Return to Bug #70153 | Download this patch
Patch Revisions:

Developer: cmb@php.net

From 853b849904d5e0db9d413c19b8615aeff7dbff70 Mon Sep 17 00:00:00 2001
From: "Christoph M. Becker" <cmb@php.net>
Date: Mon, 27 Jul 2015 16:23:16 +0200
Subject: [PATCH] Fix #70153: \DateInterval incorrectly unserialized

When unserializing DateIntervals whose days property is false, this is
converted to zero instead of the internal representation -99999. This patch
solves this issue.
---
 ext/date/php_date.c          |  6 +++++-
 ext/date/tests/bug70153.phpt | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 ext/date/tests/bug70153.phpt

diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 2f52353..79de2da 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -4115,7 +4115,11 @@ static int php_date_interval_initialize_from_hash(zval **return_value, php_inter
 		zval *z_arg = zend_hash_str_find(myht, element, sizeof(element) - 1); \
 		if (z_arg) { \
 			zend_string *str = zval_get_string(z_arg); \
-			DATE_A64I((*intobj)->diff->member, ZSTR_VAL(str)); \
+            if (str->len) { \
+                DATE_A64I((*intobj)->diff->member, ZSTR_VAL(str)); \
+            } else { \
+                (*intobj)->diff->member = -99999; \
+            } \
 			zend_string_release(str); \
 		} else { \
 			(*intobj)->diff->member = -1LL; \
diff --git a/ext/date/tests/bug70153.phpt b/ext/date/tests/bug70153.phpt
new file mode 100644
index 0000000..5b96520
--- /dev/null
+++ b/ext/date/tests/bug70153.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Bug #70153 (\DateInterval incorrectly unserialized)
+--FILE--
+<?php
+$i1 = \DateInterval::createFromDateString('+1 month');
+$i2 = unserialize(serialize($i1));
+var_dump($i1->days, $i2->days);
+var_dump($i2->special_amount, $i2->special_amount);
+?>
+--EXPECT--
+bool(false)
+bool(false)
+int(0)
+int(0)
-- 
1.9.5.msysgit.0

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 20:01:32 2024 UTC