summaryrefslogtreecommitdiff
path: root/t/18_bug_92205.t
blob: e1c14704b49c1e6d184b38281985bc6abf7427f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/perl

use strict;

BEGIN {
    $|  = 1;
    $^W = 1;
}

use Test::More tests => 32;
use t::common;
use Archive::Zip qw( :CONSTANTS );


# RT #92205: CRC error when re-writing Zip created by LibreOffice

# Archive::Zip was blowing up when processing member
# 'Configurations2/accelerator/current.xml' from the LibreOffice file. 
#
# 'current.xml' is a zero length file that has been compressed AND uses
# streaming. That means the uncompressed length is zero but the compressed
# length is greater than 0.
#
# The fix for issue #101092 added code that forced both the uncompressed &
# compressed lengths to be zero if either was zero. That caused this issue.


# This set of test checks that a zero length zip member will ALWAYS be
# mapped to a zero length Stored member, regardless of the compression
# method used or the use of streaming.
#
#
# Input files all contain a single zero length member. 
# Streaming & Compression Method are set as follows.
# 
# File                Streamed    Method
# ===============================================
# emptydef.zip        No          Deflate
# emptydefstr.zip     Yes         Deflate
# emptystore.zip      No          Store
# emptystorestr.zip   Yes         Store
#
# See t/data/mkzip.pl for the code used to create these zip files.


my @empty = map { "t/data/$_.zip" } 
            qw( emptydef emptydefstr emptystore emptystorestr );

# Implicit tests - check that stored gets used when no compression method
# has been set.
for my $infile (@empty)
{
    my $expectedout = "t/data/emptystore.zip";
    my $outfile = OUTPUTZIP;

    passthrough($infile, $outfile, sub {
        my $member = shift ;
        $member->setLastModFileDateTimeFromUnix($member->lastModTime());
     });

    my $expected = readFile($expectedout);
    my $after = readFile($outfile);

    my ($status, $reason) = testZip($outfile);
    is $status, 0, "testZip ok after $infile to $outfile"
        or warn("ziptest said: $reason\n");
    ok $expected eq $after, "$expectedout eq $outfile";
}



# Explicitly set desired compression 
for my $method ( COMPRESSION_STORED, COMPRESSION_DEFLATED)
{
    for my $infile (@empty)
    {
        my $outfile = OUTPUTZIP;
        my $expectedout = "t/data/emptystore.zip";

        passthrough($infile, $outfile, sub {
            my $member = shift ;
            $member->desiredCompressionMethod( $method );
            $member->setLastModFileDateTimeFromUnix($member->lastModTime());
         });

        my $expected = readFile($expectedout);
        my $after = readFile($outfile);

        my ($status, $reason) = testZip($outfile);
        is $status, 0, "[$method] testZip ok after $infile to $outfile"
            or warn("ziptest said: $reason\n");
        ok $after eq $expected, "[$method] $infile eq $outfile";
    }
}

# The following non-empty files should not be changed at all
my @nochange = map { "t/data/$_.zip" } 
               qw( def defstr store storestr );

for my $infile (@nochange)
{
    my $outfile = OUTPUTZIP;

    passthrough($infile, $outfile, sub {
        my $member = shift ;
        $member->setLastModFileDateTimeFromUnix($member->lastModTime());
     });

    my $expected = readFile($infile);
    my $after = readFile($outfile);

    my ($status, $reason) = testZip($outfile);
    is $status, 0, "testZip ok after $infile to $outfile"
        or warn("ziptest said: $reason\n");
    ok $expected eq $after, "$infile eq $outfile";
}