Skip to content

ext/date: Fix date error messages for embedded NULL bytes - #23363

Open
arshidkv12 wants to merge 3 commits into
php:masterfrom
arshidkv12:date-2
Open

ext/date: Fix date error messages for embedded NULL bytes#23363
arshidkv12 wants to merge 3 commits into
php:masterfrom
arshidkv12:date-2

Conversation

@arshidkv12

Copy link
Copy Markdown
Contributor

Created a separate PR: #22997

@arshidkv12
arshidkv12 requested a review from derickr as a code owner August 19, 2026 04:49
@arshidkv12 arshidkv12 changed the title ext/date: Fix date error messages for embedded NUL bytes ext/date: Fix date error messages for embedded NULL bytes Aug 19, 2026
Comment on lines +8 to +14
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

?>
--EXPECTF--
Unknown or bad format (foo%0bar) at position 0 (f) while unserializing: The timezone could not be found in the database

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}
?>
--EXPECTF--
Unknown or bad format (foo%0bar) at position 0 (f) while unserializing: The timezone could not be found in the database
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
?>
--EXPECTF--
Error: Unknown or bad format (foo%0bar) at position 0 (f) while unserializing: The timezone could not be found in the database

Comment on lines +8 to +14
} catch (ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
DatePeriod::createFromISO8601String(): Argument #1 ($specification) must not contain any null bytes No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
DatePeriod::createFromISO8601String(): Argument #1 ($specification) must not contain any null bytes
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
?>
--EXPECT--
ValueError: DatePeriod::createFromISO8601String(): Argument #1 ($specification) must not contain any null bytes

Comment on lines +10 to +16
} catch (DateMalformedStringException $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECTF--
DateTime::modify(): Failed to parse time string (foo%0bar) at position %s

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (DateMalformedStringException $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECTF--
DateTime::modify(): Failed to parse time string (foo%0bar) at position %s
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
?>
--EXPECTF--
DateMalformedStringException: DateTime::modify(): Failed to parse time string (foo%0bar) at position %s

Comment on lines +8 to +14
} catch (ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
date_default_timezone_set(): Argument #1 ($timezoneId) must not contain any null bytes No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
date_default_timezone_set(): Argument #1 ($timezoneId) must not contain any null bytes
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
?>
--EXPECT--
ValueError: date_default_timezone_set(): Argument #1 ($timezoneId) must not contain any null bytes

Stack trace:
#0 %s(%d): DateInterval->__construct('foo\x00bar')
#1 {main}
thrown in %s on line %d

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
thrown in %s on line %d
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
?>
--EXPECTF--
ValueError: DateInterval::__construct(): Argument #1 ($duration) must not contain any null bytes

Or was there a reason for catching DateMalformedIntervalStringException?

Comment on lines +6 to +14
DateInterval::createFromDateString("foo\0bar");

?>
--EXPECTF--
Fatal error: Uncaught ValueError: DateInterval::createFromDateString(): Argument #1 ($datetime) must not contain any null bytes in %s:%d
Stack trace:
#0 %s(%d): DateInterval::createFromDateString('foo\x00bar')
#1 {main}
thrown in %s on line %d No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DateInterval::createFromDateString("foo\0bar");
?>
--EXPECTF--
Fatal error: Uncaught ValueError: DateInterval::createFromDateString(): Argument #1 ($datetime) must not contain any null bytes in %s:%d
Stack trace:
#0 %s(%d): DateInterval::createFromDateString('foo\x00bar')
#1 {main}
thrown in %s on line %d
try {
DateInterval::createFromDateString("foo\0bar");
} catch(Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
?>
--EXPECTF--
ValueError: DateInterval::createFromDateString(): Argument #1 ($datetime) must not contain any null bytes

Or was there a reason for not catching?

Comment on lines +6 to +14
date_interval_create_from_date_string("foo\0bar");

?>
--EXPECTF--
Fatal error: Uncaught ValueError: date_interval_create_from_date_string(): Argument #1 ($datetime) must not contain any null bytes in %s:%d
Stack trace:
#0 %s(%d): date_interval_create_from_date_string('foo\x00bar')
#1 {main}
thrown in %s on line %d No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
date_interval_create_from_date_string("foo\0bar");
?>
--EXPECTF--
Fatal error: Uncaught ValueError: date_interval_create_from_date_string(): Argument #1 ($datetime) must not contain any null bytes in %s:%d
Stack trace:
#0 %s(%d): date_interval_create_from_date_string('foo\x00bar')
#1 {main}
thrown in %s on line %d
try {
date_interval_create_from_date_string("foo\0bar");
} catch(Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
?>
--EXPECTF--
ValueError: date_interval_create_from_date_string(): Argument #1 ($datetime) must not contain any null bytes

Or was there any reason for not catching?

Comment on lines +6 to +14
new DateTimeImmutable("foo\0bar");

?>
--EXPECTF--
Fatal error: Uncaught ValueError: DateTimeImmutable::__construct(): Argument #1 ($datetime) must not contain any null bytes in %s:%d
Stack trace:
#0 %s(%d): DateTimeImmutable->__construct('foo\x00bar')
#1 {main}
thrown in %s on line %d No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new DateTimeImmutable("foo\0bar");
?>
--EXPECTF--
Fatal error: Uncaught ValueError: DateTimeImmutable::__construct(): Argument #1 ($datetime) must not contain any null bytes in %s:%d
Stack trace:
#0 %s(%d): DateTimeImmutable->__construct('foo\x00bar')
#1 {main}
thrown in %s on line %d
try {
new DateTimeImmutable("foo\0bar");
} catch(Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
?>
--EXPECT--
ValueError: DateTimeImmutable::__construct(): Argument #1 ($datetime) must not contain any null bytes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants