diff --git a/ext/date/tests/time/duration/methods/fromIso8601DurationString.phpt b/ext/date/tests/time/duration/methods/fromIso8601DurationString.phpt index 109a1dd1307a..aee7ce5df5b0 100644 --- a/ext/date/tests/time/duration/methods/fromIso8601DurationString.phpt +++ b/ext/date/tests/time/duration/methods/fromIso8601DurationString.phpt @@ -34,10 +34,14 @@ $specifications = [ 'P1DT0S', '2000-01-01T00:00:00Z', '2000-01-01T00:00:00Z/PT1H', + + "PT5S\0garbage", + "PT5S\0", + "\0PT5S", ]; foreach ($specifications as $specification) { - printf("%-25s: ", $specification); + printf("%-25s: ", addcslashes($specification, "\0")); try { echo f(Time\Duration::fromIso8601DurationString($specification)), PHP_EOL; @@ -72,3 +76,6 @@ P1M : Time\TimeException: The ISO 8601 duration string may P1DT0S : Time\TimeException: The ISO 8601 duration string may only contain the time (T) aspect 2000-01-01T00:00:00Z : Time\TimeException: The ISO 8601 duration string is missing the period (P) aspect 2000-01-01T00:00:00Z/PT1H: Time\TimeException: The ISO 8601 duration string may only contain the period (P) aspect +PT5S\000garbage : Time\TimeException: The ISO 8601 duration string could not be parsed +PT5S\000 : Time\TimeException: The ISO 8601 duration string could not be parsed +\000PT5S : Time\TimeException: The ISO 8601 duration string could not be parsed diff --git a/ext/date/time_duration.c b/ext/date/time_duration.c index a9f69db7a3d8..937ba5c743a7 100644 --- a/ext/date/time_duration.c +++ b/ext/date/time_duration.c @@ -315,6 +315,11 @@ PHP_METHOD(Time_Duration, fromIso8601DurationString) Z_PARAM_STR(specification); ZEND_PARSE_PARAMETERS_END(); + if (zend_str_has_nul_byte(specification)) { + throw_timelib_error(TIMELIB_ERROR_ISO8601_DURATION_PARSE_FAILURE); + RETURN_THROWS(); + } + int error; timelib_duration *d = timelib_duration_create_from_iso8601string(ZSTR_VAL(specification), &error); if (error != TIMELIB_ERROR_NO_ERROR) {