[wp-trac] [WordPress Trac] #59927: Missing error check in convert_smilies() can cause PHP Fatal error
WordPress Trac
noreply at wordpress.org
Fri Nov 17 16:01:20 UTC 2023
#59927: Missing error check in convert_smilies() can cause PHP Fatal error
--------------------------+-----------------------------
Reporter: Ov3rfly | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
A client website caused PHP Fatal error, tracked it down and came to this:
{{{
PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must
be of type Countable|array, bool given in .. wp-
includes/formatting.php:3507
}}}
Which is this code:
{{{
// HTML loop taken from texturize function, could possible be
consolidated.
$textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE );
// Capture the tags as well as in between.
$stop = count( $textarr ); // Loop stuff.
}}}
The error occurs if `preg_split()` returns `false` and that is used as
argument for `count()`.
Since `false` is a valid return value here as described in PHP
documentation, there should be a check for this case.
The problem is somehow related to size of `$text` where PHP interally
obviously can't handle the data (any more).
Attached exported simplified WXR testcase. If you shorten the ''XXX''
part, the error might not appear any more.
Note: This kind of problem caused a PHP Warning with PHP 7.x but causes a
PHP Fatal error since PHP 8.x
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59927>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list