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;