This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
(perl #132147) add tests for corrupt files from tickets
authorTony Cook <tony@develop-help.com>
Tue, 6 Nov 2018 03:12:53 +0000 (14:12 +1100)
committerTony Cook <tony@develop-help.com>
Mon, 19 Nov 2018 00:27:33 +0000 (11:27 +1100)
MANIFEST
ext/SDBM_File/t/corrupt.t [new file with mode: 0644]

index f9cbd75..0062673 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -4212,6 +4212,7 @@ ext/SDBM_File/sdbm.h      SDBM kit
 ext/SDBM_File/SDBM_File.pm     SDBM extension Perl module
 ext/SDBM_File/SDBM_File.xs     SDBM extension external subroutines
 ext/SDBM_File/t/constants.t    See if SDBM_File constants work
+ext/SDBM_File/t/corrupt.t      See if SDBM_File handles corrupt files
 ext/SDBM_File/t/prep.t         See if SDBM_File with extra argument works
 ext/SDBM_File/t/sdbm.t         See if SDBM_File works
 ext/SDBM_File/tune.h   SDBM kit
diff --git a/ext/SDBM_File/t/corrupt.t b/ext/SDBM_File/t/corrupt.t
new file mode 100644 (file)
index 0000000..b4e41aa
--- /dev/null
@@ -0,0 +1,86 @@
+#!./perl
+use strict;
+use Test::More;
+use MIME::Base64;
+use File::Temp 'tempfile';
+use SDBM_File;
+use Fcntl qw(O_RDWR);
+use Errno qw(EINVAL);
+
+my ($dirfh, $dirname) = tempfile(UNLINK => 1);
+my ($pagfh, $pagname) = tempfile(UNLINK => 1);
+close $dirfh;
+close pagefh;
+
+while (my $testdata = do { local $/ = "END\n"; <DATA>; }) {
+    my ($note, $base64) = $testdata =~ /\A([^\n]+)\n(.*)/s
+      or die;
+    my $raw = decode_base64($base64);
+    open my $pagfh, ">:raw", $pagname
+      or die "Cannot recreate $pagname: $!";
+    print $pagfh $base64;
+    close $pagfh;
+    open my $dirfh, ">:raw", $dirname
+      or die "Cannot truncate $dirname: $!";
+    close $dirfh;
+
+    my %dbm;
+    my $sdbm = tie %dbm, 'SDBM_File', $dirname, O_RDWR, 0666, $pagname;
+    
+    ok(tied %dbm, "$note: tied successfully");
+    my $value = $dbm{foo};
+    pass("$note: no crash fetching a named key");
+    my $tmp;
+    for my $key (sort keys %dbm) {
+        $tmp = $dbm{$key};
+    }
+    pass("$note: no crash iterating over keys");
+    is(0+$!, EINVAL, "$note: errno set");
+    ok($sdbm->error, "$note: error flag set");
+}
+
+
+done_testing();
+
+__DATA__
+132147
+CgD+g/4D/QP8A/sD2gPZA8wDywPIAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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