[php-src] PHP-8.6: date: Validate ISO 8601 duration strings for null bytes early (#24357)

From: Date: Fri, 16 Oct 2026 09:22:13 +0000
Subject: [php-src] PHP-8.6: date: Validate ISO 8601 duration strings for null bytes early (#24357)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-142347@lists.php.net to get a copy of this message
Author: Alexander Danilov (adapik) Committer: GitHub (web-flow) Pusher: TimWolla Date: 2026-10-16T11:22:10+02:00 Commit: https://github.com/php/php-src/commit/90a271f0f4ae6c6f39047e04a06b79ae2b411864 Raw diff: https://github.com/php/php-src/commit/90a271f0f4ae6c6f39047e04a06b79ae2b411864.diff date: Validate ISO 8601 duration strings for null bytes early (#24357) Changed paths: M ext/date/tests/time/duration/methods/fromIso8601DurationString.phpt M ext/date/time_duration.c Diff: 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 8565f3e8c5f0..1365bd627af0 100644 --- a/ext/date/time_duration.c +++ b/ext/date/time_duration.c @@ -326,6 +326,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) {

« previous php.cvs (#142347) next »