Skip Menu |

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

Report information
The Basics
Id: 19643
Status: resolved
Priority: 0/
Queue: Digest-MD5

People
Owner: Nobody in particular
Requestors: p.chartrand [...] onf.ca
Cc:
AdminCc:

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



Subject: Digest::MD5 error when repeatedly invoked iin oo style mode
Summary There seems to be a bug affecting Digest::MD5 version 2.36 when called repeatedly in OO mode. The same data gives a different checksum. The procedural version does not show this behaviour. Erratic behaviour can be observed by calling repeatedly a test script. Tests were conducted on two different machines and versions of package. Test Harness for i in `seq 1 10`; do ./mk5ck.pl ; done The test script #!/usr/bin/perl #mk5ck.pl use strict; use DBI; my $data='12345678910'; &OO($data); &PROC($data); sub OO{ use Digest::MD5; my $data=shift; my $digest=new Digest::MD5; my $dig=$digest->md5_hex($data); print "Object Style: \t",$dig,"\n"; } sub PROC{ use Digest::MD5 qw(md5 md5_hex md5_base64); my $digest=new Digest::MD5; my $dig=md5_hex($data); print "Procedural Style:\t",$dig,"\n"; }
Subject: Digest MD5 error when repeatedly invoked iin oo style mode.eml.html
Digest::MD5 error when repeatedly invoked iin oo style mode Sujet: Digest::MD5 error when repeatedly invoked iin oo style modeDe: Philippe Chartrand Date: Thu, 01 Jun 2006 13:01:09 -0400Pour: gisle@ActiveState.com
Summary

There seems to be a bug affecting Digest::MD5 version 2.36 when called repeatedly in OO mode.
The same data gives a different checksum. The procedural version does not show this behaviour.
Erratic behaviour can be observed by calling repeatedly a test script. Tests were conducted on two different machines and versions of package.

Test Harness
for i in `seq 1 10`; do ./mk5ck.pl ; done


The test script


#!/usr/bin/perl
#mk5ck.pl
use strict;
use DBI;
my $data='12345678910';
&OO($data);
&PROC($data);


sub OO{
use Digest::MD5;
my $data=shift;
my $digest=new Digest::MD5;
my $dig=$digest->md5_hex($data);
print "Object Style:    \t",$dig,"\n";
}

sub PROC{
use Digest::MD5 qw(md5 md5_hex md5_base64);
my $digest=new Digest::MD5;
my $dig=md5_hex($data);
print "Procedural Style:\t",$dig,"\n";
}


Result on Mandriva (version 2.25)

[philippe@ontledroit ~]$ uname -a
Linux ontledroit.homelinux.org 2.6.12-18mdksmp #1 SMP Wed Mar 15 10:18:39 MST 2006 x86_64 AMD Opteron(tm) Processor 240 unknown GNU/Linux
[philippe@ontledroit ~]$ for i in `seq 1 10`; do ./mk5ck.pl ; done
Object Style:           b895aa73cc8e22b03e3e028e3afcf5e5
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           b895aa73cc8e22b03e3e028e3afcf5e5
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           b895aa73cc8e22b03e3e028e3afcf5e5
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           b895aa73cc8e22b03e3e028e3afcf5e5
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           b895aa73cc8e22b03e3e028e3afcf5e5
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           b895aa73cc8e22b03e3e028e3afcf5e5
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           b895aa73cc8e22b03e3e028e3afcf5e5
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           b895aa73cc8e22b03e3e028e3afcf5e5
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           b895aa73cc8e22b03e3e028e3afcf5e5
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           b895aa73cc8e22b03e3e028e3afcf5e5
Procedural Style:       432f45b44c432414d2f97df0e5743818
[philippe@ontledroit ~]$ perl -e 'use Digest::MD5;print $Digest::MD5::VERSION,"\n";'
2.25
[philippe@ontledroit ~]$

Results on RH3EL (version 2.36)

-bash-2.05b$ uname -a
Linux intranet2 2.4.21-37.ELsmp #1 SMP Wed Sep 7 13:28:55 EDT 2005 i686 i686 i386 GNU/Linux
-bash-2.05b$ for i in `seq 1 10`; do ./mk5ck.pl ; done
Object Style:           5f084ce660f2d4c524e3d5aa41f117d8
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           4204d84321e90db5df5cc39f0780972d
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           ff6f78e8717a93e70a7547e8d3524322
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           7f0c1f6bf6b850aae451875df8ef9ab7
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           9a0e38bd904eb23f9bf715d52711dc5d
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           d24de209382cd79c23263b5ffdab3752
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           cce8857a86fc98d967111b05a11258b4
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           1dc54b995732a04e64d3997d3a575961
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           f09f75d129a95e0334bc1ea445ae75d2
Procedural Style:       432f45b44c432414d2f97df0e5743818
Object Style:           392bc56627c3c8b1e543abb1aac227fd
Procedural Style:       432f45b44c432414d2f97df0e5743818
2.36-bash-2.05b$ perl -e 'use Digest::MD5;print $Digest::MD5::VERSION,"\n";'
2.36
-bash-2.05b$

Thank god I found this. I'm having the same problem. Now I removed the OO style and worked correctly. With the OO style it even doesn't create one hash correctly. It always creates 3 different hashes for the same value but none of them are correct.
On Fri Jul 07 05:58:03 2006, guest wrote: Show quoted text
> Thank god I found this. I'm having the same problem. Now I removed the > OO style and worked correctly. With the OO style it even doesn't create > one hash correctly. It always creates 3 different hashes for the same > value but none of them are correct.
I forgot to add that it happens the same thing with SHA
Show quoted text
> sub OO{ > use Digest::MD5; > my $data=shift; > my $digest=new Digest::MD5; > my $dig=$digest->md5_hex($data); > print "Object Style: \t",$dig,"\n"; > }
md5_hex() is wrong and should not be called as a method; use the 'hexdigest' method instead. Your call to md5_hex() is the same as md5_hex($digest, $data) which will calculate the digest of the stringified "$digest" value.
Correct OO way is: sub OO { my $data=shift; my $digest=new Digest::MD5; $digest->add($data); my $dig=$digest->hexdigest; print "Object Style: \t",$dig,"\n"; } IMHO, md5_hex can be modified to check if it's first argument ISA Digest::MD5. I would submit a patch, but Digest::MD5 is not pure-Perl module. -- Alexandr Ciornii, http://chorny.net
Subject: [PATCH] Digest::MD5 doesn't warn on mistaken method invocation
Here's a patch to issue a warning when 'hd5_hex' et al are called as a method on an object. The same thing was already done if it's called as a method on a class, or as a method on an object with no other args.
diff -ur Digest-MD5-2.36.orig/MD5.xs Digest-MD5-2.36/MD5.xs --- Digest-MD5-2.36.orig/MD5.xs 2005-11-26 11:06:20.000000000 +0000 +++ Digest-MD5-2.36/MD5.xs 2007-09-09 11:55:09.000000000 +0100 @@ -711,6 +711,11 @@ if (len == 11 && memEQ("Digest::MD5", data, 11)) { msg = "probably called as class method"; } + else if (SvROK(ST(0))) { + SV* sv = SvRV(ST(0)); + if (SvOBJECT(sv) && strEQ(HvNAME(SvSTASH(sv)), "Digest::MD5")) + msg = "probably called as method"; + } } if (msg) { char *f = (ix == F_BIN) ? "md5" : diff -ur Digest-MD5-2.36.orig/t/files.t Digest-MD5-2.36/t/files.t --- Digest-MD5-2.36.orig/t/files.t 2005-11-30 13:52:12.000000000 +0000 +++ Digest-MD5-2.36/t/files.t 2007-09-09 11:55:19.000000000 +0100 @@ -31,7 +31,7 @@ 628699b88b6a803225678802d2470067 Changes c95549c6c5e1e1c078b27042f1dc850f README 77503ff007841a671275fdf544dad68e MD5.pm -716c3278fd80338727c100e5d2a76795 MD5.xs +557d8fb63fb403428faea6e5aa176dfd MD5.xs 754b9db19f79dbc4992f7166eb0f37ce rfc1321.txt EOT } else { @@ -40,7 +40,7 @@ 2fdc25c326960308f5334c967455d1f5 Changes c95549c6c5e1e1c078b27042f1dc850f README 77503ff007841a671275fdf544dad68e MD5.pm -716c3278fd80338727c100e5d2a76795 MD5.xs +557d8fb63fb403428faea6e5aa176dfd MD5.xs 754b9db19f79dbc4992f7166eb0f37ce rfc1321.txt EOT }
On Sun Sep 09 06:58:56 2007, GEOFFR wrote: Show quoted text
> Here's a patch to issue a warning when 'hd5_hex' et al are called as a > method on an object. The same thing was already done if it's called as > a method on a class, or as a method on an object with no other args.
Thanks! Applied.