[gnumeric] fuzzzip: new program.



commit 894701e309a717e2212cc92be3438297cb0dcb12
Author: Morten Welinder <terra gnome org>
Date:   Wed Aug 11 14:33:47 2010 -0400

    fuzzzip: new program.

 test/ChangeLog |    4 ++
 test/fuzzzip   |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 116 insertions(+), 0 deletions(-)
---
diff --git a/test/ChangeLog b/test/ChangeLog
index 5311b9e..c7fcdfd 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,7 @@
+2010-08-11  Morten Welinder  <terra gnome org>
+
+	* fuzzzip: New fuzzer that works inside zip files.
+
 2010-08-06  Morten Welinder  <terra gnome org>
 
 	* zzufit: Log the name of the corrupted file.
diff --git a/test/fuzzzip b/test/fuzzzip
new file mode 100755
index 0000000..6c8db89
--- /dev/null
+++ b/test/fuzzzip
@@ -0,0 +1,112 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Getopt::Long;
+use File::Temp ();
+use File::Find ();
+use File::Copy ();
+use File::Spec;
+
+my $me = $0;
+$me =~ s{^.*/}{};
+
+# -----------------------------------------------------------------------------
+
+my @subfile;
+my $subfuzzer = 'fuzzxml %i %o';
+my $verbose = 0;
+
+Getopt::Long::Configure ("bundling");
+&GetOptions ("subfile=s" => \ subfile,
+	     "subfuzzer=s" => \$subfuzzer,
+	     "v|verbose" => \$verbose,
+    ) or die;
+
+my $infile = shift @ARGV;
+my $outfile = shift @ARGV;
+die "$me: usage [options] infile outfile\n" unless defined $outfile;
+
+$outfile = File::Spec->rel2abs ($outfile);
+
+die "$me: one or more subfiles should be specified with --subfile\n"
+    unless @subfile;
+
+my @quiet = $verbose ? () : ("-q");
+
+# -----------------------------------------------------------------------------
+
+my $tmpdir = File::Temp::tempdir ("fuzzzip.XXXXXX",
+				  TMPDIR => 1,
+				  CLEANUP => 1);
+
+{
+    my @cmd = ("unzip", @quiet, $infile, "-d", $tmpdir);
+    print STDERR "@cmd\n" if $verbose;
+    my $res = system (@cmd);
+    die "$me: unzipping failed.\n" unless $res == 0;
+}
+
+# -----------------------------------------------------------------------------
+
+foreach my $file (@subfile) {
+    die "Archive has no $file" unless -f "$tmpdir/$file";
+
+    my $tmpfile = "$file.tmp";
+
+    my $cmd = $subfuzzer;
+    $cmd =~ s{\%i}{$tmpdir/$file};
+    $cmd =~ s{\%o}{$tmpdir/$tmpfile};
+
+    print STDERR "$cmd\n" if $verbose;
+    my $res = system ($cmd);
+    die "$me: fuzzing failed.\n" unless $res == 0;
+
+    # system ("diff -uw $tmpdir/$tmpfile $tmpdir/$file");
+
+    rename "$tmpdir/$tmpfile", "$tmpdir/$file" or
+	die "$me: cannot renamed $tmpfile into place: $!\n";
+}
+
+# -----------------------------------------------------------------------------
+
+print STDERR "chdir $tmpdir\n" if $verbose;
+chdir $tmpdir || die "$me: cannot chdir to $tmpdir: $!\n";
+
+my @stored_files;
+my @files;
+File::Find::find (
+    sub {
+	if (-f $_) {
+	    my $name = $File::Find::name;
+	    $name =~ s{^\./}{};
+	    if ($name eq 'mimetype') {
+		push @stored_files, $name;
+	    } else {
+		push @files, $name;
+	    }
+	}
+	return 1;
+    },
+    ".");
+
+{
+    my $archive = "foo.zip";
+
+    if (@stored_files) {
+	my @cmd = ("zip", @quiet, $archive, "-0", @stored_files);
+	print STDERR "@cmd\n" if $verbose;
+	my $res = system (@cmd);
+	die "$me: zipping failed.\n" unless $res == 0;
+    }
+
+    if (@files) {
+	my @cmd = ("zip", @quiet, $archive, "-9", @files);
+	print STDERR "@cmd\n" if $verbose;
+	my $res = system (@cmd);
+	die "$me: zipping failed.\n" unless $res == 0;
+    }
+
+    &File::Copy::move ($archive, $outfile);
+}
+
+# -----------------------------------------------------------------------------



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]