This file is indexed.

/usr/share/perl5/Archive/Any/Lite.pm is in libarchive-any-lite-perl 0.11-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package Archive::Any::Lite;

use strict;
use warnings;
use File::Spec;

our $VERSION = '0.11';
our $IGNORE_SYMLINK;

sub new {
  my ($class, $file, $opts) = @_;

  $file = File::Spec->rel2abs($file);
  unless (-f $file) {
    warn "$file not found\n";
    return;
  }

  # just for undocumented backward compat
  my $type = !ref $opts ? $opts : '';

  # XXX: trust file extensions until I manage to make File::MMagic
  #      more reliable while fork()ing or I happen to find a decent
  #      and portable alternative to File::MMagic.

  my $handler =
    ($type && lc $type eq 'tar') || $file =~ /\.(?:tar|tar\.(?:gz|bz2)|gtar|tgz)$/ ? 'Archive::Any::Lite::Tar' :
    ($type && lc $type eq 'zip') || $file =~ /\.(?:zip)$/ ? 'Archive::Any::Lite::Zip' : undef;
  unless ($handler) {
    warn "No handler available for $file\n";
    return;
  }

  bless {
    file    => $file,
    handler => $handler,
    opts    => ref $opts ? $opts : undef,
  }, $class;
}

sub extract {
  my ($self, $dir, $opts) = @_;

  $self->{handler}->extract($self->{file}, $dir, $opts || $self->{opts});
}

sub files {
  my $self = shift;
  $self->{handler}->files($self->{file});
}

sub is_impolite {
  my $self = shift;

  my @files       = $self->files;
  my $first_file  = $files[0];
  my ($first_dir) = File::Spec->splitdir($first_file);

  return grep( !/^\Q$first_dir\E/, @files ) ? 1 : 0;
}

sub is_naughty {
  my ($self) = shift;
  return ( grep { m{^(?:/|(?:\./)*\.\./)} } $self->files ) ? 1 : 0;
}

sub type {
  my $self = shift;
  my ($type) = lc $self->{handler} =~ /::(\w+)$/;
  return $type;
}

package Archive::Any::Lite::Tar;
use Archive::Tar;

sub files {
  my ($self, $file) = @_;
  Archive::Tar->list_archive($file);
}

sub extract {
  my ($self, $file, $dir, $opts) = @_;
  $dir = '.' unless defined $dir;
  $dir = File::Spec->rel2abs($dir);
  my $tar = Archive::Tar->new;
  my $fh;
  if ($file =~ /\.(tgz|tar\.gz)$/) {
    require IO::Zlib;
    $fh = IO::Zlib->new($file, "rb") or do { warn "$file: $!"; return };
  }
  elsif ($file =~ /\.tar.bz2$/) {
    require IO::Uncompress::Bunzip2;
    $fh = IO::Uncompress::Bunzip2->new($file) or do { warn "$file: $!"; return };
  }
  else {
    open $fh, '<', $file or do { warn "$file: $!"; return };
    binmode $fh;
  }

  # Archive::Tar is too noisy when an archive has minor glitches.
  # Note also that $file can't hold the last error.
  local $Archive::Tar::WARN;
  my %errors;
  my $has_extracted;
  my %read_opts = (limit => 1);
  if ($opts) {
    for (qw/limit md5 filter filter_cb extract/) {
      if (exists $opts->{"tar_$_"}) {
        $read_opts{$_} = $opts->{"tar_$_"};
      }
      elsif (exists $opts->{$_}) {
        $read_opts{$_} = $opts->{$_};
      }
    }
  }
  until (eof $fh) {
    my @files = $tar->read($fh, undef, \%read_opts);
    if (my $error = $tar->error) {
      warn $error unless $errors{$error}++;
    }
    if (!@files && !$has_extracted) {
      warn "No data could be read from $file";
      return;
    }
    for my $file (@files) {
      next if $IGNORE_SYMLINK && ($file->is_symlink or $file->is_hardlink);
      my $path = File::Spec->catfile($dir, $file->prefix, $file->name);
      $tar->extract_file($file, File::Spec->canonpath($path)) or do {
        if (my $error = $tar->error) {
          warn $error unless $errors{$error}++;
        }
      };
    }
    $has_extracted += @files;
  }
  return if %errors;
  return 1;
}

sub type { 'tar' }

package Archive::Any::Lite::Zip;
use Archive::Zip qw/:ERROR_CODES/;

sub files {
  my ($self, $file) = @_;
  my $zip = Archive::Zip->new($file) or return;
  $zip->memberNames;
}

sub extract {
  my ($self, $file, $dir, $opts) = @_;
  my $zip = Archive::Zip->new($file) or return;
  $dir = '.' unless defined $dir;
  my $error = 0;
  for my $member ($zip->members) {
    next if $IGNORE_SYMLINK && $member->isSymbolicLink;
    my $path = File::Spec->catfile($dir, $member->fileName);
    my $ret = $member->extractToFileNamed(File::Spec->canonpath($path));
    $error++ if $ret != AZ_OK;
  }
  return if $error;
  return 1;
}

sub type { 'zip' }

1;

__END__

=head1 NAME

Archive::Any::Lite - simple CPAN package extractor

=head1 SYNOPSIS

    use strict;
    use warnings;
    use Archive::Any::Lite;

    local $Archive::Any::Lite::IGNORE_SYMLINK = 1; # for safety

    my $tarball = 'foo.tar.gz';
    my $archive = Archive::Any::Lite->new($tarball);
    $archive->extract('into/some/directory/');

=head1 DESCRIPTION

This is a fork of L<Archive::Any> by Michael Schwern and Clint Moore. The main difference is this works properly even when you fork(), and may require less memory to extract a tarball. On the other hand, this isn't pluggable (this only supports file formats used in the CPAN toolchains), and this doesn't check mime types (at least as of this writing).

=head1 METHODS

=head2 new

  my $archive = Archive::Any::Lite->new($archive_file);
  my $archive = Archive::Any::Lite->new($archive_file, {tar_filter => qr/foo/});

Creates an object.
You can pass an optional hash reference for finer control.

=head2 extract

  $archive->extract;
  $archive->extract($directory);
  $archive->extract($directory, {tar_filter => qr/foo/});

Extracts the files in the archive to the given $directory. If no $directory is given, it will go into the current working directory.

You can pass an optional hash reference for finer control. If passed, options passed in C<new> will be ignored.

=head2 files

  my @file = $archive->files;

A list of files in the archive.

=head2 is_impolite

  my $is_impolite = $archive->is_impolite;

Checks to see if this archive is going to unpack into the current directory rather than create its own.

=head2 is_naughty

  my $is_naughty = $archive->is_naughty;

Checks to see if this archive is going to unpack outside the current directory.

=head2 type

Deprecated. For backward compatibility only.

=head1 GLOBAL VARIABLE

=head2 $IGNORE_SYMLINK

If set to true, symlinks (and hardlinks for tarball) will be ignored.

=head1 SEE ALSO

L<Archive::Any>, L<Archive::Tar::Streamed>

=head1 AUTHOR

L<Archive::Any> is written by Michael G Schwern and Clint Moore.

Kenichi Ishigaki, E<lt>ishigaki@cpan.orgE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2012 by Kenichi Ishigaki.

This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=cut