Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: andrew [...] cpan.org
Cc:
AdminCc:

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



Subject: Unable to restore context on "even" numbers
Date: Sat, 3 Oct 2015 17:53:18 -0700
To: bug-Digest-MD5 [...] rt.cpan.org
From: Andrew Fresh <andrew [...] cpan.org>
I was looking at the new feature to save and restore context and couldn't get it to work reliably. Attached is a test that reproduces what I was seeing, and the output that I see failing. I am not actually planning to use the feature, just updating the OpenBSD patch that replaces the guts with our own MD5 implementation. This new feature is making me look a lot more deeply at it. https://github.com/afresh1/OpenBSD-perl/blob/master/patches/GOOD/use_our_MD5.patch This is stock perl built with plenv, without any patches. $ perl -v This is perl 5, version 22, subversion 0 (v5.22.0) built for OpenBSD.amd64-openbsd Copyright 1987-2015, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page. $ prove context.t context.t .. 1/? # Failed test '64 saved context' # at context.t line 34. # got: '7ec34ef5239493ac5691b0332ddeb5f5' # expected: 'e510683b3f5ffe4093d021808bc6ff70' # Failed test '128 saved context' # at context.t line 34. # got: 'eebed3a8b0902a31bef75702ce0658f3' # expected: '81109eec5aa1a284fb5327b10e9c16b9' # Failed test '1024 saved context' # at context.t line 34. # got: 'e4b3d870eedc254fde025cae4bbe66a3' # expected: 'b7ea2d21ad2ef3e28085d30247603e0b' # Failed test '2048 saved context' # at context.t line 34. # got: '2cd034df0b74c92cb64ccfa6751bedcd' # expected: '21a199c53f422a380e20b162fb6ebe9c' # Looks like you failed 4 tests of 31. context.t .. Dubious, test returned 4 (wstat 1024, 0x400) Failed 4/31 subtests Test Summary Report ------------------- context.t (Wstat: 1024 Tests: 31 Failed: 4) Failed tests: 21, 24, 27, 30 Non-zero exit status: 4 Files=1, Tests=31, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.03 cusr 0.01 csys = 0.07 CPU) Result: FAIL
#!/usr/bin/perl use strict; use warnings; use Test::More; use Digest::MD5; foreach my $string ( map { 'a' x $_ } 1..17, 31..33, 64..65, 127..129, 1023..1025, 2047..2049, ) { my $expect = do { my $ctx = Digest::MD5->new; $ctx->add($string); $ctx->add($string); $ctx->hexdigest; }; my $got = do { my $ctx1 = Digest::MD5->new; $ctx1->add($string); my $ctx2 = Digest::MD5->new; $ctx2->context( $ctx1->context ); $ctx2->add($string); $ctx2->hexdigest; }; is $got, $expect, length($string) . " saved context"; } done_testing;
Subject: [rt.cpan.org #107528] Problem is in multiples of 64
Date: Sun, 4 Oct 2015 13:13:03 -0700
To: Bugs in Digest-MD5 via RT <bug-Digest-MD5 [...] rt.cpan.org>
From: Andrew Fresh <andrew [...] afresh1.com>
Realized that it's actually every 64 characters that it fails, so 192, and whatnot. This is on a 64bit version of perl, but I haven't had a chance to try it on a 32bit version.
From: ozcoder [...] gmail.com
On Sun Oct 04 16:13:27 2015, andrew@afresh1.com wrote: Show quoted text
> Realized that it's actually every 64 characters that it fails, so 192, > and whatnot. This is on a 64bit version of perl, but I haven't had a > chance to try it on a 32bit version.
I don't think that will ever work the way you want. The doc says "returns a 3-element list: number of blocks processed, a 16-byte internal state buffer, then up to 63 bytes of unprocessed data.", so you are missing the data from longer than 63 character strings. Gordon
Subject: Re: [rt.cpan.org #107528] Unable to restore context on "even" numbers
Date: Sat, 12 Mar 2016 14:17:36 -0700
To: bug-Digest-MD5 [...] rt.cpan.org
From: Andrew Fresh <andrew [...] afresh1.com>
On Mon, Feb 01, 2016 at 01:45:00AM -0500, ozcoder@gmail.com via RT wrote: Show quoted text
> I don't think that will ever work the way you want. The doc says "returns a 3-element list: number of blocks processed, a 16-byte > internal state buffer, then up to 63 bytes of unprocessed data.", so you are missing the data from longer than 63 character strings.
I read it that the third element will be at most the 63 bytes that haven't yet been processed. I think the bug is when we hit the point where we should have processed all the data, instead of returning nothing, it returns garbage, far more than the 63 bytes max you would expect. I made the included test pass by setting the third element of the context returned by $ctx1->context and $ctx2->context to an empty string instead of what is returned if the length of either of the third elements ends up greater than 63. It will fail again if you comment out the two lines that set $context?[2] = ''. Whatever the case and solution, the modified test (attached) passes (most of the time) for me. It crashes from time to time still, but that could be another issue.
#!/usr/bin/perl use strict; use warnings; use Test::More; use Digest::MD5; foreach my $length ( 1..17, 31..33, 64..65, 127..129, 191..193, 1023..1025, 2047..2049, ) { my $string = 'a' x $length; my $expect = do { my $ctx = Digest::MD5->new; $ctx->add($string); $ctx->add($string); $ctx->add($string); $ctx->hexdigest; }; my $got = do { my $ctx1 = Digest::MD5->new; $ctx1->add($string); my @context1 = $ctx1->context; my $reset = length($context1[2]) > 63; $context1[2] = '' if $reset; my $ctx2 = Digest::MD5->new; $ctx2->context( @context1 ); $ctx2->add($string); my @context2 = $ctx2->context; $context2[2] = '' if $reset or length($context2[2]) > 63; my $ctx3 = Digest::MD5->new; $ctx3->context( @context2 ); $ctx3->add($string); $ctx3->hexdigest; }; is $got, $expect, "[$length] saved context"; } done_testing;
Unsure if it it just went unnoticed due to location, but I did submit a patch in a pull-request on github: https://github.com/gisle/digest-md5/pull/12