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
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,
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.
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
From: ppisar [...] redhat.com
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
Subject: 0001-Fix-reading-IV-with-new-lines-from-a-file.patch
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
From: ppisar [...] redhat.com
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
Subject: Crypt-CipherSaber-1.01-Fix-reading-IV-with-new-lines-from-a-file.patch
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.