]> granicus.if.org Git - php/commitdiff
Ensure hash_update_stream() always returns the same hash when $length = 0
authorSymeon Charalabides <symeon@systasis.com>
Mon, 20 Apr 2020 23:44:57 +0000 (01:44 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Tue, 21 Apr 2020 06:55:15 +0000 (08:55 +0200)
ext/hash/tests/hash_update_stream_basic_001.phpt [new file with mode: 0644]

diff --git a/ext/hash/tests/hash_update_stream_basic_001.phpt b/ext/hash/tests/hash_update_stream_basic_001.phpt
new file mode 100644 (file)
index 0000000..c145784
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+Ensure hash_update_stream() always returns the same hash when $length = 0
+--CREDITS--
+Symeon Charalabides <symeon@systasis.com> - @phpdublin
+--SKIPIF--
+<?php
+if (!extension_loaded('openssl')) die('skip openssl extension not available');
+?>
+--FILE--
+<?php
+
+for ($j=0; $j<3; $j++)
+{
+    // Create pseudo-random hash
+    $bytes = openssl_random_pseudo_bytes(15, $cstrong);
+    $hash   = sha1(bin2hex($bytes));
+
+    // Create temp file with hash
+    $fp = tmpfile();
+    fwrite($fp, $hash);
+    rewind($fp);
+
+    // Stream it with 0 length and output hash
+    $ctx = hash_init('md5');
+    hash_update_stream($ctx, $fp, 0);
+    echo hash_final($ctx) . "\n";
+}
+
+?>
+--EXPECT--
+d41d8cd98f00b204e9800998ecf8427e
+d41d8cd98f00b204e9800998ecf8427e
+d41d8cd98f00b204e9800998ecf8427e