1--TEST-- 2Ensure hash_update_stream() always returns the same hash when $length = 0 3--CREDITS-- 4Symeon Charalabides <symeon@systasis.com> - @phpdublin 5--SKIPIF-- 6<?php 7if (!extension_loaded('openssl')) die('skip openssl extension not available'); 8?> 9--FILE-- 10<?php 11 12for ($j=0; $j<3; $j++) 13{ 14 // Create pseudo-random hash 15 $bytes = openssl_random_pseudo_bytes(15, $cstrong); 16 $hash = sha1(bin2hex($bytes)); 17 18 // Create temp file with hash 19 $fp = tmpfile(); 20 fwrite($fp, $hash); 21 rewind($fp); 22 23 // Stream it with 0 length and output hash 24 $ctx = hash_init('md5'); 25 hash_update_stream($ctx, $fp, 0); 26 echo hash_final($ctx) . "\n"; 27} 28 29?> 30--EXPECT-- 31d41d8cd98f00b204e9800998ecf8427e 32d41d8cd98f00b204e9800998ecf8427e 33d41d8cd98f00b204e9800998ecf8427e 34