Skip Menu |
 

This queue is for tickets about the Crypt-CipherSaber CPAN distribution.

Report information
The Basics
Id: 28370
Status: open
Priority: 0/
Queue: Crypt-CipherSaber

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

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

Attachments
0001-Fix-reading-IV-with-new-lines-from-a-file.patch
Crypt-CipherSaber-1.01-Fix-reading-IV-with-new-lines-from-a-file.patch



Subject: Randomness in test results? PASS 158 : FAIL 6
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Type: text/plain; charset="utf8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 295
Download (untitled) / with headers
text/plain 295b
I now have test 164 test results for C:CS and I have 6 fails. Today I looked if I could reproduce today's failure with the same perl version but I could not. It seems there is some randomness involved. Maybe you can try to run the test suite about 60 times to reproduce one failure? Regards,
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Disposition: inline
Charset: utf8
Message-Id: <rt-3.6.HEAD-24551-1196128238-1562.28370-0-0 [...] rt.cpan.org>
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Original-Encoding: utf-8
Content-Length: 470
Download (untitled) / with headers
text/plain 470b
Ping? I'm now at PASS 300 : FAIL 16. What would you think? Is it just a problem is the testing or in the module itself? Here is the test that is output from the failing test. Not very helpful: t/fh_encrypt........ # Failed test 'autogenerating and autoreading IV should also round-trip' # at t/fh_encrypt.t line 115. # Looks like you failed 1 test of 6. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/6 subtests And as the last time not reproducable.
MIME-Version: 1.0
In-Reply-To: <rt-3.6.HEAD-24551-1196128238-1562.28370-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.6.HEAD-24551-1196128238-1562.28370-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-17364-1327689278-340.28370-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 324
Download (untitled) / with headers
text/plain 324b
On Mon Nov 26 20:50:38 2007, ANDK wrote: Show quoted text
> I'm now at PASS 300 : FAIL 16. > > What would you think? Is it just a problem is the testing or in the > module itself?
Error is in sub fh_crypt. It appears when IV contains \n. while (<$in>) { ( $iv, $_ ) = unpack( "a10a*", $_ ); -- Alexandr Ciornii, http://chorny.net
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-17364-1327689278-340.28370-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
X-RT-Interface: API
References: <rt-3.6.HEAD-24551-1196128238-1562.28370-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-17364-1327689278-340.28370-0-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1409147172-16620-2"
Message-ID: <rt-4.0.18-16620-1409147172-768.0-0-0 [...] rt.cpan.org>
Message-ID: <rt-4.0.18-16620-1409147172-1126.28370-0-0 [...] rt.cpan.org>
X-RT-Original-Encoding: utf-8
From: ppisar [...] redhat.com
Content-Length: 0
Content-Disposition: inline
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 398
Download (untitled) / with headers
text/plain 398b
Dne Pá 27.led.2012 13:34:38, CHORNY napsal(a): Show quoted text
> On Mon Nov 26 20:50:38 2007, ANDK wrote: >
> > I'm now at PASS 300 : FAIL 16. > > > > What would you think? Is it just a problem is the testing or in the > > module itself?
> > Error is in sub fh_crypt. It appears when IV contains \n. > > while (<$in>) > { > ( $iv, $_ ) = unpack( "a10a*", $_ ); >
Attached patch should fix it. -- Petr
MIME-Version: 1.0
Subject: 0001-Fix-reading-IV-with-new-lines-from-a-file.patch
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Type: text/x-patch; name="0001-Fix-reading-IV-with-new-lines-from-a-file.patch"
Content-Disposition: inline; filename="0001-Fix-reading-IV-with-new-lines-from-a-file.patch"
Content-Transfer-Encoding: binary
Content-Length: 3158
From e72a35d3276239d98161f4818e764fc419635bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com> Date: Wed, 27 Aug 2014 15:38:54 +0200 Subject: [PATCH] Fix reading IV with new-lines from a file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Decrypting filehandle data by fh_crypt() could produce bad decrypted data if the initizalization vector read from the filehandle contained a new-line character. This caused random failures of 'autogenerating and autoreading IV should also round-trip' test in t/fh_encrypt.t. This patch fixes it by reading first 10 characters regardless of current line separator. CPAN RT #28370 Signed-off-by: Petr Písař <ppisar@redhat.com> --- lib/Crypt/CipherSaber.pm | 14 +++++++++----- t/fh_encrypt.t | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/lib/Crypt/CipherSaber.pm b/lib/Crypt/CipherSaber.pm index 99f362b..2dd91f8 100644 --- a/lib/Crypt/CipherSaber.pm +++ b/lib/Crypt/CipherSaber.pm @@ -67,6 +67,15 @@ sub fh_crypt $iv = $self->_gen_iv() if length($iv) == 1; $self->_setup_key($iv); print OUT $iv; + } else { + if ( 10 != $in->read($iv, 10) ) + { + require Carp; + Carp::carp( 'Could not read IV from input filehandle' ); + return; + } + ( $iv ) = unpack( "a10", $iv ); + $self->_setup_key($iv); } my $state = $self->[1]; @@ -75,11 +84,6 @@ sub fh_crypt while (<$in>) { - unless ($iv) - { - ( $iv, $_ ) = unpack( "a10a*", $_ ); - $self->_setup_key($iv); - } my $line; ( $line, $state, @vars ) = _do_crypt( $state, $_, @vars ); print OUT $line; diff --git a/t/fh_encrypt.t b/t/fh_encrypt.t index 35a74fb..e595ff9 100644 --- a/t/fh_encrypt.t +++ b/t/fh_encrypt.t @@ -6,7 +6,7 @@ BEGIN } use strict; -use Test::More tests => 6; +use Test::More tests => 7; use_ok( 'Crypt::CipherSaber' ); # tests the fh_crypt() method @@ -114,6 +114,44 @@ while (<SOURCE>) ok( ! $status, 'autogenerating and autoreading IV should also round-trip' ); +# IV retrieved from encrypted file can contain new-line characters. Check that +# fh_encrypt can deal with it +{ + local $/ = "\012"; + + open( IN, 'smiles.png' ) or die "Cannot read smiles.png: $!"; + open( OUT, '> smiles_2.cs1' ) or die "Cannot write to smiles_2.cs1: $!"; + binmode( IN ); + binmode( OUT ); + $cs->fh_crypt( \*IN, \*OUT, $/ x 10 ); + close IN; + close OUT; + + open( IN, 'smiles_2.cs1' ) or die "Cannot read smiles_2.cs1: $!"; + open( OUT, '> smiles_2.png' ) or die "Cannot write to smiles_2.png $!"; + binmode( IN ); + binmode( OUT ); + $cs->fh_crypt( \*IN, \*OUT ); + close IN; + close OUT; + + open( SOURCE, 'smiles.png' ) or die "Cannot read smiles.png: $!"; + open( DEST, 'smiles_2.png' ) or die "Cannot read smiles_2.png: $!"; + binmode SOURCE; + binmode DEST; + $status = 0; + while (<SOURCE>) + { + unless ($_ eq <DEST>) + { + $status = 1; + last; + } + } + ok( ! $status, 'IV with new-lines in the encrypted file' ); +} + + END { 1 while unlink qw( smiles_2.cs1 smiles_2.png outsmiles.cs1 outsmiles.png ); -- 1.9.3
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-16620-1409147172-768.0-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
X-RT-Interface: API
References: <rt-3.6.HEAD-24551-1196128238-1562.28370-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-17364-1327689278-340.28370-0-0 [...] rt.cpan.org> <rt-4.0.18-16620-1409147172-768.0-0-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1440765829-2827-2"
Message-ID: <rt-4.0.18-2827-1440765829-1632.0-0-0 [...] rt.cpan.org>
Message-ID: <rt-4.0.18-2827-1440765829-1398.28370-0-0 [...] rt.cpan.org>
X-RT-Original-Encoding: utf-8
From: ppisar [...] redhat.com
Content-Length: 0
Content-Disposition: inline
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 513
Download (untitled) / with headers
text/plain 513b
Dne St 27.srp.2014 09:46:12, ppisar napsal(a): Show quoted text
> Dne Pá 27.led.2012 13:34:38, CHORNY napsal(a):
> > On Mon Nov 26 20:50:38 2007, ANDK wrote: > >
> > > I'm now at PASS 300 : FAIL 16. > > > > > > What would you think? Is it just a problem is the testing or in the > > > module itself?
> > > > Error is in sub fh_crypt. It appears when IV contains \n. > > > > while (<$in>) > > { > > ( $iv, $_ ) = unpack( "a10a*", $_ ); > >
> Attached patch should fix it. >
Patch rebased to 1.01 is attached. -- Petr
MIME-Version: 1.0
Subject: Crypt-CipherSaber-1.01-Fix-reading-IV-with-new-lines-from-a-file.patch
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Type: application/octet-stream; name="Crypt-CipherSaber-1.01-Fix-reading-IV-with-new-lines-from-a-file.patch"
Content-Disposition: inline; filename="Crypt-CipherSaber-1.01-Fix-reading-IV-with-new-lines-from-a-file.patch"
Content-Transfer-Encoding: base64
Content-Length: 3302
From 399dc2e20b241e772fa16defcc2e2dbe063ac290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com> Date: Wed, 27 Aug 2014 15:38:54 +0200 Subject: [PATCH] Fix reading IV with new-lines from a file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Decrypting filehandle data by fh_crypt() could produce bad decrypted data if the initizalization vector read from the filehandle contained a new-line character. This caused random failures of 'autogenerating and autoreading IV should also round-trip' test in t/fh_encrypt.t. This patch fixes it by reading first 10 characters regardless of current line separator. CPAN RT #28370 Signed-off-by: Petr Písař <ppisar@redhat.com> --- lib/Crypt/CipherSaber.pm | 14 +++++++++----- t/fh_encrypt.t | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/lib/Crypt/CipherSaber.pm b/lib/Crypt/CipherSaber.pm index 7cb7cc0..2db153c 100644 --- a/lib/Crypt/CipherSaber.pm +++ b/lib/Crypt/CipherSaber.pm @@ -67,6 +67,15 @@ sub fh_crypt $iv = $self->_gen_iv() if length($iv) == 1; $self->_setup_key($iv); print OUT $iv; + } else { + if ( 10 != $in->read($iv, 10) ) + { + require Carp; + Carp::carp( 'Could not read IV from input filehandle' ); + return; + } + ( $iv ) = unpack( "a10", $iv ); + $self->_setup_key($iv); } my $state = $self->[1]; @@ -75,11 +84,6 @@ sub fh_crypt while (<$in>) { - unless ($iv) - { - ( $iv, $_ ) = unpack( "a10a*", $_ ); - $self->_setup_key($iv); - } my $line; ( $line, $state, @vars ) = _do_crypt( $state, $_, @vars ); print OUT $line; diff --git a/t/fh_encrypt.t b/t/fh_encrypt.t index 35a74fb..e595ff9 100644 --- a/t/fh_encrypt.t +++ b/t/fh_encrypt.t @@ -6,7 +6,7 @@ BEGIN } use strict; -use Test::More tests => 6; +use Test::More tests => 7; use_ok( 'Crypt::CipherSaber' ); # tests the fh_crypt() method @@ -114,6 +114,44 @@ while (<SOURCE>) ok( ! $status, 'autogenerating and autoreading IV should also round-trip' ); +# IV retrieved from encrypted file can contain new-line characters. Check that +# fh_encrypt can deal with it +{ + local $/ = "\012"; + + open( IN, 'smiles.png' ) or die "Cannot read smiles.png: $!"; + open( OUT, '> smiles_2.cs1' ) or die "Cannot write to smiles_2.cs1: $!"; + binmode( IN ); + binmode( OUT ); + $cs->fh_crypt( \*IN, \*OUT, $/ x 10 ); + close IN; + close OUT; + + open( IN, 'smiles_2.cs1' ) or die "Cannot read smiles_2.cs1: $!"; + open( OUT, '> smiles_2.png' ) or die "Cannot write to smiles_2.png $!"; + binmode( IN ); + binmode( OUT ); + $cs->fh_crypt( \*IN, \*OUT ); + close IN; + close OUT; + + open( SOURCE, 'smiles.png' ) or die "Cannot read smiles.png: $!"; + open( DEST, 'smiles_2.png' ) or die "Cannot read smiles_2.png: $!"; + binmode SOURCE; + binmode DEST; + $status = 0; + while (<SOURCE>) + { + unless ($_ eq <DEST>) + { + $status = 1; + last; + } + } + ok( ! $status, 'IV with new-lines in the encrypted file' ); +} + + END { 1 while unlink qw( smiles_2.cs1 smiles_2.png outsmiles.cs1 outsmiles.png ); -- 2.4.3


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.