Skip to content

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

Closed

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

  1. ndossche commented on Dec 11, 2023

    @ndossche
    Member

    Looks like it's using unsigned int in some places... I'll check them all.

  2. self-assigned this
    on Dec 11, 2023
  3. added 2 commits that reference this issue on Dec 12, 2023
    2b8c008
    cd17917
  4. added a commit that references this issue on Dec 12, 2023
    0917a36
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