~ubuntu-branches/ubuntu/vivid/libarchive-zip-perl/vivid-proposed

« back to all changes in this revision

Viewing changes to examples/zipcheck.pl

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2004-10-30 22:19:15 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20041030221915-gtxn2xoojblyekyh
Tags: 1.14-1
* New upstream version.
  - Fixes: Archive::Zip is fooled by manipulated ZIP directory
    Closes: #277773.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/perl -w
 
2
# usage: valid zipname.zip
 
3
# exits with non-zero status if invalid zip
 
4
# status = 1: invalid arguments
 
5
# status = 2: generic error somewhere
 
6
# status = 3: format error
 
7
# status = 4: IO error
 
8
use strict;
 
9
use Archive::Zip qw(:ERROR_CODES);
 
10
use IO::Handle;
 
11
use File::Spec;
 
12
 
 
13
# instead of stack dump:
 
14
Archive::Zip::setErrorHandler( sub { warn shift() } );
 
15
 
 
16
my $nullFileName = File::Spec->devnull();
 
17
my $zip = Archive::Zip->new();
 
18
my $zipName = shift(@ARGV) || exit 1;
 
19
eval
 
20
{
 
21
        my $status = $zip->read( $zipName );
 
22
        exit $status if $status != AZ_OK;
 
23
};
 
24
if ($@) { warn 'error reading zip:', $@, "\n"; exit 2 }
 
25
 
 
26
eval
 
27
{
 
28
        foreach my $member ($zip->members)
 
29
        {
 
30
                my $fh = IO::File->new();
 
31
                $fh->open(">$nullFileName") || die "can't open $nullFileName\: $!\n";
 
32
                my $status = $member->extractToFileHandle($fh);
 
33
                if ($status != AZ_OK)
 
34
                {
 
35
                        warn "Extracting ", $member->fileName(), " from $zipName failed\n";
 
36
                        exit $status;
 
37
                }
 
38
        }
 
39
}