Skip to content

calculates incorrect MD5 with large scalars [rt.cpan.org #123185] #6

@toddr

Description

@toddr

Migrated from rt.cpan.org#123185 (status was 'new')

From @jmdh on 2017-10-03 13:54:31
:
Forwarding from https://bugs.debian.org/877369:

Digest::MD5 calculates the wrong MD5 for large scalars:

$ perl -e 'print "\x00" x 1024 x 1024 x 1024 x 9'|md5sum -
97606009c3309d3a0b4b40ae9fadc720  -

$ perl -MDigest::MD5 -E 'say Digest::MD5::md5_hex "\x00" x 1024 x 1024 x 1024 x 9'
e02694e929aec3068ff272bebe0ae0a4

This is likely due to buggy length calculation in MD5.xs, which fails for
large values of "len" (and hasn't changed for 5.26):

    ctx->bytes_low += len;
    if (ctx->bytes_low < len) /* wrap around */
        ctx->bytes_high++;

Note that I couldn't reproduce this myself as I got an out of memory error (on a machine with 16GB of RAM). The problem does not occur when adding the data 1GB at a time using the OO interface.

Digest::MD5 is at 2.54, unmodified by Debian.

Thanks for your work on maintaining Digest::MD5!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions