Bug #78654 [NEW]: Incorrectly computed opcache checksum on files with non-ascii characters

From: 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 = ['°','₀','۰','0','¹','₁','۱','1','²','₂','۲','2','³','₃','۳','3','⁴','₄','۴','٤', '4','⁵','₅','۵','٥','5','⁶','₆','۶','٦','6','⁷','₇','۷','7','⁸','₈','۸','8', '⁹','₉','۹','9','à','á','ả','ã','ạ','ă','ắ','ằ','ẳ','ẵ','ặ','â','ấ','ầ','ẩ','ẫ', 'ᾆ','ᾇ','ὰ','ά','ᾰ','ᾱ','ᾲ','ᾳ','ᾴ','ᾶ','ᾷ','а','ﺃ','အ','ာ','ါ','ǻ','ǎ','ª','ა','अ ','ﺍ','a','ä','б','β','ﺏ','ဗ','ბ','b','ç','ć','č','ĉ','ċ','c','ď','ð','đ','ƌ', 'ȡ','ɖ','ɗ','ᵭ','ᶁ','ᶑ','д','δ','ﺩ','ﺽ','ဍ','ဒ','დ','d','é','è','ẻ','ẽ','ẹ','ê', 'ľ','ĺ','ļ','ŀ','л','λ','ﻝ','လ','ლ','l','м','μ','ﻡ','မ','მ','m','ñ','ń','ň', 'ộ','ơ','ớ','ờ','ở','ỡ','ợ','ø','ō','ő','ŏ','ο','ὀ','ὁ','ὂ','ὃ','ὄ','ὅ','ὸ', 'ũ','ụ','ư','ứ','ừ','ử','ữ','ự','û','ū','ů','ű','ŭ','ų','µ','у','ဉ','ု','ူ','ǔ', 'Ĩ','Ị','Î','Ï','Ī','Ĭ','Į','İ','Ι','Ί','Ϊ','Ἰ','Ἱ','Ἳ','Ἴ','Ἵ','Ἶ','Ἷ','Ῐ','Ῑ', 'Ὶ','Ί','И','І','Ї','Ǐ','ϒ','I','J','К','Κ','K','Ĺ','Ł','Л','Λ','Ļ','Ľ','Ŀ', 'Ὃ','Ὄ','Ὅ','Ὸ','Ό','О','Θ','Ө','Ǒ','Ǿ','O','Ö','П','Π','P','Q','Ř','Ŕ','Р', 'Ÿ','Ῠ','Ῡ','Ὺ','Ύ','Ы','Й','Υ','Ϋ','Ŷ','Y','Ź','Ž','Ż','З','Ζ','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

« previous php.bugs (#223150) next »