Skip to content

Commit d554d91

Browse files
symeoncmb69
authored andcommitted
Ensure hash_update_stream() always returns the same hash when $length = 0
1 parent 321d9d9 commit d554d91

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Ensure hash_update_stream() always returns the same hash when $length = 0
3+
--CREDITS--
4+
Symeon Charalabides <symeon@systasis.com> - @phpdublin
5+
--SKIPIF--
6+
<?php
7+
if (!extension_loaded('openssl')) die('skip openssl extension not available');
8+
?>
9+
--FILE--
10+
<?php
11+
12+
for ($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--
31+
d41d8cd98f00b204e9800998ecf8427e
32+
d41d8cd98f00b204e9800998ecf8427e
33+
d41d8cd98f00b204e9800998ecf8427e

0 commit comments

Comments
 (0)