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