Page MenuHomePhabricator

Serialization of 'Wikimedia\Parsoid\DOM\Element' is not allowed - PHP 8.1
Closed, ResolvedPublicBUG REPORT

Description

The issue is easily reproduced in the context of parse.php logging, but needs to be audited more carefully to avoid issues in other places.

Steps to replicate the issue:

Using PHP 8.1.5 (Ubuntu):

$ echo "hello" | php bin/parse.php --wt2wt --debug=wts

What happens?:

[... start of WTS trace ...]
Exception from line 89 of /home/isa-wmf/gitrepo/parsoid/src/Utils/Utils.php: Serialization of 'Wikimedia\Parsoid\DOM\Element' is not allowed
#0 /home/isa-wmf/gitrepo/parsoid/src/Utils/Utils.php(89): serialize()
#1 /home/isa-wmf/gitrepo/parsoid/src/Html2Wt/Separators.php(569): Wikimedia\Parsoid\Utils\Utils::clone()

What should have happened instead?:
It shouldn't have crashed.

Note that if debug logging is activated on a Mediawiki install, and if this triggers somehow, it can also make the request crash with a 500, which is less than ideal.

Notes

This is probably related to https://github.com/php/php-src/commit/ca94d55a19da2c92f9812d3f2dd8172fb8b9c52b, which makes DOM classes as not serializable in PHP 8.1. It's unclear to me whether we want to make our subclasses serializable (and whether that will work - https://github.com/php/php-src/issues/8996 seems to indicate it will not work with any build of 8.1) or avoid serializing DOM classes.

Event Timeline

Change 858390 had a related patch set uploaded (by Subramanya Sastry; author: Subramanya Sastry):

[mediawiki/services/parsoid@master] Use native cloning on DOMNode in Util::clone

https://gerrit.wikimedia.org/r/858390

Change 858390 merged by jenkins-bot:

[mediawiki/services/parsoid@master] Utils::clone: Support limited DOMNode cloning during debugging

https://gerrit.wikimedia.org/r/858390

ssastry triaged this task as Medium priority.
ssastry moved this task from Needs Triage to Bugs & Crashers on the Parsoid board.
ssastry moved this task from Backlog to To Deploy on the Content-Transform-Team-WIP board.

Change 861464 had a related patch set uploaded (by Arlolra; author: Arlolra):

[mediawiki/vendor@master] Bump parsoid to 0.17.0-a7

https://gerrit.wikimedia.org/r/861464

Change 861464 merged by jenkins-bot:

[mediawiki/vendor@master] Bump parsoid to 0.17.0-a7

https://gerrit.wikimedia.org/r/861464

Change 861472 had a related patch set uploaded (by C. Scott Ananian; author: Arlolra):

[mediawiki/vendor@wmf/1.40.0-wmf.12] Bump parsoid to 0.17.0-a7

https://gerrit.wikimedia.org/r/861472

Change 861472 merged by jenkins-bot:

[mediawiki/vendor@wmf/1.40.0-wmf.12] Bump parsoid to 0.17.0-a7

https://gerrit.wikimedia.org/r/861472