Skip Menu |

This queue is for tickets about the Digest-MD5 CPAN distribution.

Report information
The Basics
Id: 79197
Status: rejected
Priority: 0/
Queue: Digest-MD5

People
Owner: Nobody in particular
Requestors: a.pankov [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Digest::MD5 changing it's internal state after calling hexdigest
Date: Fri, 24 Aug 2012 19:46:50 +0300
To: bug-Digest-MD5 [...] rt.cpan.org
From: Andrey Pankov <a.pankov [...] gmail.com>
Here is example script and test run on some binary file: [andrey@vaio:~]-» md5sum Sellador.mp3 66911197cbd06414f6d0a8fd66077676 Sellador.mp3 [andrey@vaio:~]-» perl md5.pl Sellador.mp3 66911197cbd06414f6d0a8fd66077676 Sellador.mp3 d41d8cd98f00b204e9800998ecf8427e Sellador.mp3 d41d8cd98f00b204e9800998ecf8427e Sellador.mp3 [andrey@vaio:~]-» cat md5.pl use Digest::MD5; $ctx = Digest::MD5->new; $file = $ARGV[0]; open $fh, '<', $file; $ctx->addfile($fh); close $fh; $digest = $ctx->hexdigest; print "$digest\t$file\n"; $digest = $ctx->hexdigest; print "$digest\t$file\n"; $digest = $ctx->hexdigest; print "$digest\t$file\n"; [andrey@vaio:~]-» uname -a Linux vaio 2.6.38-15-generic #64-Ubuntu SMP Fri Jul 6 18:51:28 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux [andrey@vaio:~]-» perl -v This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi -- Regards, Andrey V. Pankov mailto:a.pankov@gmail.com
 This is the documented behaviour. When you call any of the 'digest' methods the state of the context object is automatically reset.  This is documented under the '$md5->digest' entry.  I agree that's not the most sane behaviour, but that was how the initial interface was specified so we kept it like this.

The workaround if you don't want the state to change is to call:

  $hash =  $md5->clone->hexdigest;