Fix checksum calculation for opcache #4804
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://bugs.php.net/bug.php?id=78654
The checksum can be incorrectly computed when a file to be cached contains non-ascii characters. When the opcache computes the checksum before it writes the file it chains together two calls to zend_adler32.
https://github.com/php/php-src/blob/PHP-7.2.24/ext/opcache/zend_file_cache.c#L870
When the bin file containing the opcache is loaded it computes the checksum with a single call to zend_adler32.
https://github.com/php/php-src/blob/PHP-7.2.24/ext/opcache/zend_file_cache.c#L1461
The zend_adler32 function uses signed chars instead of unsigned chars. As a result non-ascii characters can have negative values. This means the checksum is incorrectly computed and chained calls can result in different values than a single call to zend_adler32.
https://github.com/php/php-src/blob/PHP-7.2.24/ext/opcache/zend_accelerator_util_funcs.c#L738
Added two pieces of additional logging. The first is to show when the opcache is load from a file into to memory. The second is to show the expect and actual checksums when when a file does not fails the check.