[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strtok() fails to tokenize the input when passed a literal string when opcache is enabled #13145

Closed
TRowbotham opened this issue Jan 14, 2024 · 5 comments

Comments

@TRowbotham
Copy link
Contributor

Description

The following code:

<?php
$tok = strtok("This is\tan example\nstring", " \n\t");

while ($tok !== false) {
    $tok = strtok(" \n\t");
}

Resulted in this output:

Infinite loop

But I expected this output instead:

Not an infinite loop

The above code results in an infinite loop on PHP 8.3.x and master when opcache is enabled. It works as expected on PHP 8.1.x and 8.2.x with opcache enabled. It also works as expected when opcache is disabled on PHP 8.3.x and master.

If you change the example to use a variable as input instead of a literal string, then it works as expected on PHP 8.3.x and master when opcache is enabled.

<?php
$string = "This is\tan example\nstring";
$tok = strtok($string, " \n\t");

while ($tok !== false) {
    $tok = strtok(" \n\t");
}

PHP Version

PHP 8.3.1

Operating System

Ubuntu 20.04/WSL

@iluuu1994
Copy link
Member

Hi @TRowbotham! Thanks for the report. This seems to be optimization-related, since opcache.optimization_level=0 dodges the issue. I'll have a look today.

iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Jan 14, 2024
@SjonHortensius
Copy link
Contributor

@iluuu1994 your fix seems incomplete - with 8.3.2 we are seeing other strange issues with strtok and state interference.

The above testcase (still) fails on 8.3.2 when running under php-fpm

@iluuu1994
Copy link
Member

@SjonHortensius I think this commit is only scheduled for 8.3.3.

@SjonHortensius
Copy link
Contributor

@SjonHortensius I think this commit is only scheduled for 8.3.3.

thanks - in that case we are experiencing another strtok issue wrt global state that only appeared in 8.3.2 but we're having trouble creating a testcase unfortunately. Will post a separate issue if we do

@iluuu1994
Copy link
Member

@SjonHortensius It's very likely that these are related. Can you try on 8.3.3?

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

No branches or pull requests

3 participants