Req #80214 [NEW]: random_bytes(): 0 random bytes should be a valid request

From: Date: Sat, 10 Oct 2020 12:34:50 +0000
Subject: Req #80214 [NEW]: random_bytes(): 0 random bytes should be a valid request
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229505@lists.php.net to get a copy of this message
From: divinity76 at gmail dot com Operating system: PHP version: Next Minor Version Package: Unknown/Other Function Bug Type: Feature/Change Request Bug description:random_bytes(): 0 random bytes should be a valid request Description: ------------ asking random_bytes() for 0 random bytes should be a perfectly valid request (but asking for <0 bytes should not be), there are situations where code will dynamically determine that they need "0 random bytes", and then ask random_bytes to get them the number of bytes they determined that they needed (as a real-life example of this, check https://3v4l.org/OCBiU , and to make that code runnable, go to line 35 and replace for($i=0;$i<100;++$i){ with for($i=1;$i<100;++$i){ ) but random_bytes will throw an Error when users ask for 0 random bytes. that should be a perfectly valid request, why is it throwing an Error? when you run str_repeat("",0) or hex2bin("") or bin2hex("") or base64_decode("") or base64_encode("") or fwrite($h,"") or file_put_contents("file",""), none of those requests are errors, why is it then an error to ask for 0 random bytes? Test script: --------------- <?php for($i=0;$i<9;++$i){ random_bytes($i); } echo "success!"; Expected result: ---------------- success! Actual result: -------------- Fatal error: Uncaught Error: Length must be greater than 0 in /in/elLeT:4 Stack trace: #0 /in/elLeT(4): random_bytes(0) #1 {main} thrown in /in/elLeT on line 4 Process exited with code 255. -- Edit bug report at https://bugs.php.net/bug.php?id=80214&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80214&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80214&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80214&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80214&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80214&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80214&r=support Expected behavior: https://bugs.php.net/fix.php?id=80214&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80214&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80214&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80214&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80214&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80214&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80214&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80214&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80214&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80214&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80214&r=mysqlcfg

« previous php.bugs (#229505) next »