1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/ext/date/tests/bug81500.phpt
Christoph M. Becker 866adb122a Fix #81500: Interval serialization regression since 7.3.14 / 7.4.2
While it may not be desired, `DateInterval::$f` supports negative
values, at least with regard to calculations.  We still need to guard
from assigning double values which are out of range for signed 64bit
integers (which would be undefined behavior).  zend_dval_to_lval() does
this by returning `0` instead of triggering UB.  This way we can avoid
setting the invalid marker, which doesn't work as expected anyway.

We must not do that only for unserialization, but also when the property
is set in the first place.

We need to adapt some of the existing tests wrt. this behavior.  In
particular, we check for an arbitrary value in bug79015.phpt, to cater
to differences between 32bit and 64bit architectures.

Closes GH-7575.
2021-10-15 19:08:07 +02:00

17 lines
338 B
PHP

--TEST--
Bug #81500 (Interval serialization regression since 7.3.14 / 7.4.2)
--FILE--
<?php
$interval = new DateInterval('PT1S');
$interval->f = -0.000001;
var_dump($interval->s, $interval->f);
$interval = unserialize(serialize($interval));
var_dump($interval->s, $interval->f);
?>
--EXPECT--
int(1)
float(-1.0E-6)
int(1)
float(-1.0E-6)