Skip to content

Fix GH-20503: Assertion failure with ext/date DateInterval property hash construction - #20720

Merged
arnaud-lb merged 1 commit into
php:PHP-8.4from
heathdutton:fix-gh-20503
Oct 15, 2026
Merged

arnaud-lb merged 1 commit into
php:PHP-8.4from
heathdutton:fix-gh-20503

Conversation

@heathdutton

@heathdutton heathdutton commented Dec 16, 2025 •

Copy link
Copy Markdown
Contributor

A DateInterval that references itself trips an assertion in json_encode() on debug builds. date_object_get_properties_interval writes into the properties table in place. While json_encode() walks the cycle, that table is shared (refcount > 1), so zend_hash_str_update() asserts.

Now the handler separates the table first and writes the copy back to obj->properties, so it doesn't leak.

A direct self-reference ends in "Maximum stack depth exceeded" now, same as DateTime. A cycle through an array still reports "Recursion detected".

Fixes GH-20503

@arnaud-lb arnaud-lb left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @heathdutton! The approach looks right, but please check comments. (Edit: Please change the base of the PR to PHP-8.3. The branch is based on 8.3, but not the PR.)

Comment thread ext/date/tests/bug-gh20503.phpt Outdated
Comment thread ext/date/php_date.c Outdated
@arnaud-lb

Copy link
Copy Markdown
Member

NB: In master, DateInterval could be greatly simplified by using standard object properties and removing all the prop handlers.

@heathdutton
heathdutton changed the base branch from master to PHP-8.3 December 19, 2025 17:01
@heathdutton
heathdutton marked this pull request as draft December 19, 2025 17:03
@heathdutton
heathdutton force-pushed the fix-gh-20503 branch 3 times, most recently from 2af857e to 6ec27cd Compare December 19, 2025 18:14
@heathdutton
heathdutton force-pushed the fix-gh-20503 branch 3 times, most recently from 9b65615 to 6dfc863 Compare December 25, 2025 01:57
@heathdutton

heathdutton commented Dec 25, 2025 •

Copy link
Copy Markdown
Contributor Author

I tried adding the refcount check to get_properties_interval, but it leaks memory - the duplicated HashTable has no owner to free it. Other routes I tried produced ABI break, so I reverted a bit to get us passed the block. The ABI break label no longer applies.

@heathdutton
heathdutton marked this pull request as ready for review December 25, 2025 03:33
@heathdutton
heathdutton changed the base branch from PHP-8.3 to PHP-8.4 October 5, 2026 16:31
@heathdutton

Copy link
Copy Markdown
Contributor Author

Reworked per your suggestion. get_properties_interval now separates the table when it's shared and writes the dup back to obj->properties (that was the leak I hit before). The get_properties_for handler is gone, and the test uses the json_encode() repro, which aborts without the fix.

A direct self-reference now ends in "Maximum stack depth exceeded", same as DateTime. Moved the base to PHP-8.4 since 8.3 is security-only now. Mind another look when you get a chance?

@arnaud-lb arnaud-lb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me otherwise

Comment thread ext/date/php_date.c Outdated
@arnaud-lb
arnaud-lb merged commit 7ffbf30 into php:PHP-8.4 Oct 15, 2026
17 of 18 checks passed
arnaud-lb added a commit that referenced this pull request Oct 15, 2026
* PHP-8.6:
  [ci skip] NEWS
  Fix GH-20503: Assertion failure with ext/date DateInterval property hash (#20720)
@arnaud-lb

Copy link
Copy Markdown
Member

Thank you!

wheakerd pushed a commit to wheakerd/php-src that referenced this pull request Oct 15, 2026
* PHP-8.4:
  [ci skip] NEWS
  Fix phpGH-20503: Assertion failure with ext/date DateInterval property hash (php#20720)
wheakerd pushed a commit to wheakerd/php-src that referenced this pull request Oct 15, 2026
* PHP-8.5:
  [ci skip] NEWS
  Fix phpGH-20503: Assertion failure with ext/date DateInterval property hash (php#20720)
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.

Assertion failure with ext/date DateInterval property hash construction

2 participants