Bug #72100 [NEW]: implode() inserts garbage into resulting string when joins very big integer

From: Date: Mon, 25 Apr 2016 09:09:09 +0000
Subject: Bug #72100 [NEW]: implode() inserts garbage into resulting string when joins very big integer
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200757@lists.php.net to get a copy of this message
From: mikhail dot galanin at yahoo dot com Operating system: SLES x86_64 PHP version: 7.0.5 Package: Scripting Engine problem Bug Type: Bug Bug description:implode() inserts garbage into resulting string when joins very big integer Description: ------------ In the implode() implementation, there's an optimisation that operates when input array contains long's. This optimisation relays on the fact that log10(num) returns digit number of string representation of "num". Even though mathematically it is correct there an issue when num consist of more than 14 nines (i.e. 99999999999999999). In this case the log10 is rounded up and actual result gets wrong. Test script: --------------- $a = [ 'INSERT IGNORE INTO ', 'Table', (999999999999999999), PHP_INT_MIN, PHP_INT_MAX ]; $str = implode(' ', $a); echo json_encode(["str" => $str]); Expected result: ---------------- {"str":"INSERT IGNORE INTO Table 999999999999999999 -9223372036854775808 9223372036854775807"} Actual result: -------------- {"str":"INSERT IGNORE INTO \u0000 Table 999999999999999999 -9223372036854775808 9223372036854775807"} -- Edit bug report at https://bugs.php.net/bug.php?id=72100&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72100&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72100&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72100&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=72100&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=72100&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=72100&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=72100&r=needscript Try newer version: https://bugs.php.net/fix.php?id=72100&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=72100&r=support Expected behavior: https://bugs.php.net/fix.php?id=72100&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=72100&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=72100&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=72100&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72100&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=72100&r=dst IIS Stability: https://bugs.php.net/fix.php?id=72100&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=72100&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=72100&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=72100&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=72100&r=mysqlcfg

« previous php.bugs (#200757) next »