Bug #78654 [NEW]: Incorrectly computed opcache checksum on files with non-ascii characters
| From: | mhagstrand at gmail dot com | Date: | Wed, 09 Oct 2019 07:52:20 +0000 |
| Subject: | Bug #78654 [NEW]: Incorrectly computed opcache checksum on files with non-ascii characters | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-223150@lists.php.net to get a copy of this message | ||
From: mhagstrand at gmail dot com
Operating system:
PHP version: 7.2.23
Package: opcache
Bug Type: Bug
Bug description:Incorrectly computed opcache checksum on files with non-ascii characters
Description:
------------
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
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
Test script:
---------------
Ini settings
opcache.enable=1
opcache.enable_cli=1
opcache.file_cache=/tmp
opcache.log_verbosity_level=3
<?php
$mbChars =
['°','â','Û°','ï¼','¹','â','Û±','ï¼','²','â','Û²','ï¼','³','â','Û³','ï¼','â´','â','Û´','Ù¤',
'ï¼','âµ','â
','Ûµ','Ù¥','ï¼','â¶','â','Û¶','Ù¦','ï¼','â·','â','Û·','ï¼','â¸','â','Û¸','ï¼',
'â¹','â','Û¹','ï¼','à ','á','ả','ã','ạ','Ä','ắ','ằ','ẳ','ẵ','ặ','â','ấ','ầ','ẩ','ẫ',
'á¾','á¾','á½°','ά','á¾°','á¾±','á¾²','á¾³','á¾´','á¾¶','á¾·','а','ïº','á¡','á¬','á«','Ç»','Ç','ª','á','à¤
','ïº','ï½','ä','б','β','ïº','á','á','ï½','ç','Ä','Ä','Ä','Ä','ï½','Ä','ð','Ä','Æ',
'È¡','É','É','áµ','á¶','á¶','д','δ','ﺩ','ﺽ','á','á','á','ï½','é','è','ẻ','ẽ','ẹ','ê',
'ľ','ĺ','ļ','Å','л','λ','ï»','á','á','ï½','м','μ','ﻡ','á','á','ï½','ñ','Å','Å',
'á»','Æ¡','á»','á»','á»','ỡ','ợ','ø','Å','Å','Å','ο','á½','á½','á½','á½','á½','á½
','ὸ',
'Å©','ụ','ư','ứ','ừ','á»','ữ','á»±','û','Å«','ů','ű','Å','ų','µ','Ñ','á','á¯','á°','Ç',
'Ĩ','á»','Ã','Ã','Ī','Ĭ','Ä®','İ','Î','Î','Ϊ','Ἰ','á¼¹','á¼»','á¼¼','á¼½','á¼¾','Ἷ','á¿','á¿',
'á¿','Î','Ð','Ð','Ð','Ç','Ï','I','J','Ð','Î','K','Ĺ','Å','Ð','Î','Ä»','Ľ','Ä¿',
'á½','á½','á½','Ὸ','Î','Ð','Î','Ó¨','Ç','Ǿ','O','Ã','Ð','Î ','ï¼°','ï¼±','Å','Å','Ð ',
'Ÿ','Ῠ','á¿©','Ὺ','Î','Ы','Ð','Î¥','Ϋ','Ŷ','ï¼¹','Ź','Ž','Å»','Ð','Î','Z','Ã','Ǽ',
'Ч','Ð','Ð','Ä','Ĥ','IJ','Ä´','Ð¥','Ð','Ð','Å','Ψ','Ш','Щ','áº','Ã','Ц','Я','Ю',
'Ð','Â ','â','â','â','â','â','â
','â','â','â','â','â','â¯','â','ã','ï¾ '];
echo "Hello World\n";
?>
Expected result:
----------------
When the opcache is loaded from a file the checksum in the file matches
the computed checksum. No warning about a corrupted file in the logs.
Actual result:
--------------
In the opcache log the following warning shows up if the opcache bin
file exists.
Warning corrupted file
'/tmp/285d13c8bcb81a2cb747f9609f2e9b08/opt/php-src/ext/opcache/tests/adler32_checksum.php.bin'
--
Edit bug report at https://bugs.php.net/bug.php?id=78654&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78654&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78654&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78654&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78654&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78654&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78654&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78654&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78654&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78654&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78654&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78654&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78654&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78654&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78654&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78654&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78654&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78654&r=mysqlcfg