Skip to content

hash() function hangs endlessly if using sha512 on strings >= 4GiB #12936

Description

@bug-fix0r

Description

The following script hangs endlessly.

<?php $t = time();
echo hash("sha512", str_repeat("x", 1024*1024*1024*4-1));
echo "\ncalculating hash took ".(time() - $t)."s\n";
$t = time();
echo hash("sha512", str_repeat("x", 1024*1024*1024*4));
echo "\ncalculating hash took ".(time() - $t)."s\n"; ?>

Resulted in this output:

f918f25f32fe81f274619743e661a4158f176384d74b46bce7c4305f160119ce727204db2910ff287535ca2e40c2a98f2d23b40c82afbcca750a532b9843e3bc
calculating hash took 14s

But I expected this output instead:

f918f25f32fe81f274619743e661a4158f176384d74b46bce7c4305f160119ce727204db2910ff287535ca2e40c2a98f2d23b40c82afbcca750a532b9843e3bc
calculating hash took 14s
...hash goes here...
calculating hash took 14s

PHP Version

PHP 8.2.10-2ubuntu1 (cli) (built: Sep 5 2023 14:37:47) (NTS)

Operating System

KUbuntu 23.10

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions