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

[lintian] 01/02: t: Provide a more convincing corrupt zip file



This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch stretch
in repository lintian.

commit 18db6604f25863923c715b5f307084e95963434b
Author: Niels Thykier <niels@thykier.net>
Date:   Sun Apr 30 11:24:22 2017 +0000

    t: Provide a more convincing corrupt zip file
    
    Signed-off-by: Niels Thykier <niels@thykier.net>
---
 debian/changelog                                |  3 ++
 t/tests/java-jars/debian/debian/rules           |  4 +--
 t/tests/java-jars/debian/generate-unparsable.pl | 37 +++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 4cf6b44..5a45ab0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -33,6 +33,9 @@ lintian (2.5.50.1) unstable; urgency=medium
     + [EB] Fix failing tests by making the fake flash object more
       convincing.  The most recent version of libmagic uses a more precise
       definition of the data within a flash file.  (Closes: #852891)
+  * t/tests/java-jars:
+    + [NT] Provide a more convincing corrupt .zip file that also fools
+      file 5.30.
 
   * vendors/ubuntu/main/data/changes-file/known-dists:
     + [CW] Add zesty.
diff --git a/t/tests/java-jars/debian/debian/rules b/t/tests/java-jars/debian/debian/rules
index b4951f9..4811f4b 100755
--- a/t/tests/java-jars/debian/debian/rules
+++ b/t/tests/java-jars/debian/debian/rules
@@ -8,10 +8,10 @@ override_jh_build:
 	unzip testa.jar
 	zip -r codeless.jar META-INF/
 	zip -r manifestless.jar org/
-	printf "PK\003\004Watch the fireworks begin :>" > unparsable.jar
+	perl generate-unparsable.pl
 
+# Skip - it chokes on "unparsable.jar" and we don't need it
 override_jh_manifest override_jh_depends override_dh_strip_nondeterminism:
-	# Skip - it chokes on "unparsable.jar" and we don't need it
 
 override_dh_auto_clean:
 	rm -fr META-INF/ org/
diff --git a/t/tests/java-jars/debian/generate-unparsable.pl b/t/tests/java-jars/debian/generate-unparsable.pl
new file mode 100644
index 0000000..405d272
--- /dev/null
+++ b/t/tests/java-jars/debian/generate-unparsable.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use autodie;
+
+# Generated with "hexdump -C <valid-file.zip> | head -n 10".  Should
+# be a valid header of a truncated zip file.  This is enough to fool
+# file 5.30 and earlier, but will obviously break if you try to parse
+# it in full.
+my $valid_header = <<'EOF';
+00000000  50 4b 03 04 0a 00 00 00  00 00 4c 59 9e 4a 00 00  |PK........LY.J..|
+00000010  00 00 00 00 00 00 00 00  00 00 04 00 1c 00 6f 72  |..............or|
+00000020  67 2f 55 54 09 00 03 20  c6 05 59 20 c6 05 59 75  |g/UT... ..Y ..Yu|
+00000030  78 0b 00 01 04 e8 03 00  00 04 e8 03 00 00 50 4b  |x.............PK|
+00000040  03 04 0a 00 00 00 00 00  4c 59 9e 4a 00 00 00 00  |........LY.J....|
+00000050  00 00 00 00 00 00 00 00  0b 00 1c 00 6f 72 67 2f  |............org/|
+00000060  64 65 62 69 61 6e 2f 55  54 09 00 03 20 c6 05 59  |debian/UT... ..Y|
+00000070  20 c6 05 59 75 78 0b 00  01 04 e8 03 00 00 04 e8  | ..Yux..........|
+00000080  03 00 00 50 4b 03 04 0a  00 00 00 00 00 4c 59 9e  |...PK........LY.|
+00000090  4a 00 00 00 00 00 00 00  00 00 00 00 00 13 00 1c  |J...............|
+EOF
+
+open(my $fd, '>', 'unparsable.jar');
+
+for my $line (split(m/\n/, $valid_header)) {
+    chomp($line);
+    next if $line =~ s/^\s*+(?:\#.*)?$//;
+    next if $line !~ s/^[0-9a-fA-F]+\s+//; # Remove leading "offset"
+    $line =~ s/\s*(?:\|.+\|\s*)?$//; # Remove trailing "display" part (if present)
+    for my $byte (split(m/\s++/, $line)) {
+        printf {$fd} '%c', hex($byte);
+    }
+}
+
+close($fd);
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git


Reply to: