Skip to content

bz2: Fix truncation of total output size causing erroneous errors#20807

Closed
ndossche wants to merge 2 commits intophp:PHP-8.4from
ndossche:bz2-sucks
Closed

bz2: Fix truncation of total output size causing erroneous errors#20807
ndossche wants to merge 2 commits intophp:PHP-8.4from
ndossche:bz2-sucks

Conversation

@ndossche
Copy link
Member

Also switch to uint64_t as that's used on master and makes the code simpler to fix.

@ndossche ndossche marked this pull request as ready for review December 31, 2025 11:01
Copy link
Member

@arnaud-lb arnaud-lb left a comment

Choose a reason for hiding this comment

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

I get that this fixes the scaling of total_out_hi32, which was broken because the operation has unsigned int result type. This also backports #20807.

This looks right to me.

It seems worth it to add a test:

$compressed_file = 'test.bz2';
$sum = 'd4b5e52ed34a774fa645f94369b0c61375436d30';

/*
    $fd = popen("bzip2 > $compressed_file", "w");
    for ($i = 0; $i < 8; $i++) {
        fwrite($fd, str_repeat((string)$i, 2**30));
    }
    fclose($fd);
*/

var_dump(sha1(bzdecompress(file_get_contents($compressed_file))) === $sum);

test.bz2 is 8KiB, so we can embed it to save some time.

@ndossche
Copy link
Member Author

ndossche commented Jan 2, 2026

Thanks. The test will consume a lot of memory though so perhaps we should postpone merging this until #20762 & co are resolved

@arnaud-lb
Copy link
Member

Yes this seems reasonable

Also switch to uint64_t as that's used on master and makes the code
simpler to fix.

Co-authored-by: Arnaud Le Blanc <arnaud.lb@gmail.com>
@ndossche ndossche closed this in 4ee95fc Feb 27, 2026
@iluuu1994
Copy link
Member

@ndossche
Copy link
Member Author

ASAN could simply be skipped, it's not too surprising it performs worse.

Agreed

Though it also failed for a macOS release job. I presume the test can't be meaningfully made cheaper?

Not really, we need to cross the 4GiB boundary to reproduce the issue. I don't know why macOS fails.

@iluuu1994
Copy link
Member

How quickly does the test run on your machine? Given this was limited to macOS apart from ASAN, maybe it's ok to just skip it there as well, assuming the fix is not platform-dependent.

@ndossche
Copy link
Member Author

ndossche commented Feb 28, 2026

Fix isn't platform dependent. I pushed some extra changes to the SKIPIF.
Takes around 41s on my i7-4790, on a release build

@iluuu1994
Copy link
Member

@ndossche Thanks! The timeout doesn't seem too surprising then. The run-tests.php timeout can be controlled through the TEST_TIMEOUT env var, but only for all tests. Another option might be to allow increasing this on a test-by-test basis. I'm happy with the SKIPIF though.

@ndossche
Copy link
Member Author

We'll see if the issue reoccurs and can take action then

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.

3 participants