|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-06-23 07:22 UTC] ab@php.net
Description: ------------ When passing an integer that overflows PHP_INT_MAX in 32-bit, the behavior of chr() differs. The documentation currently doesn't define what should happen in this situation, the only statement is that chr() expects an ASCII code. chr() should ensure the input is in the valid range, thus making the behavior consistent between 32- and 64-bit. Test script: --------------- Debug\php.exe -r "$a = chr(2632627629); var_dump($a, ord($a));" string(1) " " int(0) x64\Debug\php.exe -r "$a = chr(2632627629); var_dump($a, ord($a));" string(1) "ยก" int(173) Expected result: ---------------- string(1) " " int(0) Actual result: -------------- Different behavior depending on 32- or 64-bit build. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 01:00:01 2025 UTC |
Hi Bob, hi Anatol, I reported that problem while talking to Anatol about another bug by email. We really had such code which got broken by this change. So technically it is a BC break but I'm not sure if we are the only one trapping into that issue? We encountered the problem in an Ascii85 encoder which we fixed now by casting to int explicity. So I don't have a problem with this BC break as we've a fix for it: $r = 0; for ($j = 0; $j < 5; ++$j) { $r = (int)($r * 85 + $chn[$j]); } $out .= chr($r >> 24) . chr($r >> 16) . chr($r >> 8) . chr($r); Anyhow this problem will only arise in special situations and will not be recognized until it happens (in our case PDF documents that uses an Ascii85 filter - very rare), which may lead people to think that the code is fine with PHP 7 while it is not... Here are some os projects/packages which current versions are affected: https://packagist.org/search/?q=fpdi https://packagist.org/search/?q=mpdf https://packagist.org/search/?q=pdfparser (depends on https://packagist.org/search/?q=tcpdf which seems to use such structure in its filter class/method, too - which is actually only used by the pdfparser) Additionally there are some hundreds packages depending on these packages, too. If you want to stay with this BC break this have to be documentated. At our end this would force people to update not only to PHP 7 but to the latest library version. So I'm fine with this BC break. Anyhow it could end in some trouble around these packages and users. Cheers, Jan