Bug #79222 [NEW]: unread_bytes do not work
From: skullnobrains at gmail dot com
Operating system: linux
PHP version: 7.2.27
Package: Sockets related
Bug Type: Bug
Bug description:unread_bytes do not work
Description:
------------
i am directly connecting to a mysql server using stream socket
functions.
when there is something to read, stream_get_meta_data() reports 0 bytes
to read, and 255 when there is nothing to read.
i tried multiple 7.x versions and ended up with similar results : 7.2.7
, 7.3 , and a few others
Test script:
---------------
function my_msg_r($sock){
echo "===== READ =====\n";
var_dump(stream_get_meta_data($sock)['unread_bytes']);
$header=stream_socket_recvfrom($sock, 4, STREAM_PEEK);
my_od($header);
if(4!==strlen($header))
return my_wrn("failed to read a complete packet header");
$len=my_str2int(substr($header,0,3));
if($len===0xffffff)return my_wrn("i do not handle packets longer than
2pow24 yet, sorry");
printf("READ LEN %s 0x%x\n",$len,$len);
printf("READ SEQ %u\n",ord($header[3]));
/* TODO CHECK THE SEQUENCE NUMBER : THE CALLER SHOULD PASS THE EXPECTED
SEQ NUMBER AND WRITE AN OUT OF ORDER ERROR IF SOMETHING GOES WRONG */
/* TODO CHECK WE HAVE ENOUGH UNREAD BYTES OR AT LEAST WHAT LENGTH WE
MANAGED TO READ */
//if($n===0xffffff)return fread($sock,$n).my_msg_r($sock); # TODO
proper error handling + this is not compatible with async operations
return substr(fread($sock,$len+4),4); # TODO proper error handling !
}
/* i am not including my_od which merely produces the lines starting
with od : one line per character with the increment, decimal ascii code,
ascii character, and hex value and have no relation with the bug. this
looks like an old 5.6 bug i stumbled upon many years ago and was fixed
*/
Actual result:
--------------
===== READ =====
int(0)
od 0 7 111
od 1 0 0
od 2 0 0
od 3 2 10
READ LEN 7 0x7
READ SEQ 2
CONNECTED AND AUTHENTICATED : Resource id #2
===== WRITE =====
od 0 15 1111
od 1 0 0
od 2 0 0
od 3 0 0
WRITE LEN=15
WRITE SEQ=0
===== READ =====
int(0)
od 0 1 1
od 1 0 0
od 2 0 0
od 3 1 1
READ LEN 1 0x1
READ SEQ 1
field count=1
===== READ =====
int(255)
... a this point, i hit ctrl+c because there is and won't be anything to
read
--
Edit bug report at https://bugs.php.net/bug.php?id=79222&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79222&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79222&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79222&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79222&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79222&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79222&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79222&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79222&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79222&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79222&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79222&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79222&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79222&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79222&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79222&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79222&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79222&r=mysqlcfg
Thread (7 messages)
- skullnobrains at gmail dot com