]> granicus.if.org Git - zziplib/blob - test/zziptests.py
CVE-2017-5975 testcase
[zziplib] / test / zziptests.py
1 import unittest
2 import subprocess
3 import logging
4 import os
5 import collections
6 import shutil
7 import random
8 import re
9 from fnmatch import fnmatchcase as matches
10 from cStringIO import StringIO
11
12 logg = logging.getLogger("test")
13
14 topsrcdir = "../.."
15 testdatadir = "testdata.d"
16 readme = "README"
17 mkzip = "zip"
18 unzip = "unzip"
19 exeext = ""
20
21 def shell_string(command):
22    return " ".join(["'%s'" % arg.replace("'","\\'") for arg in command])
23
24 def shell(command, shell=True, calls=False, cwd=None, env=None, lang=None, returncodes=None):
25     returncodes = returncodes or [ None, 0 ]
26     Shell = collections.namedtuple("Shell",["returncode", "output", "errors", "shell"])
27     if isinstance(command, basestring):
28        sh_command = command
29        command = [ command ]
30     else:
31        sh_command = shell_string(command)
32     if lang:
33         if not env: env = os.environ.copy()
34         for name, value in env.items():
35             if name.startswith("LC_"):
36                 env[name] = lang
37         env["LANG"] = lang # defines message format
38         env["LC_ALL"] = lang # other locale formats
39     try:
40         output, errors = "", ""
41         if calls:
42             logg.debug("result from %s: %s", cwd and cwd+"/" or "shell", sh_command)
43             run = subprocess.Popen(command, shell=shell, cwd=cwd, env=env)
44             if run.returncode:
45                 logg.warning("EXIT %s: %s", run.returncode, command)
46             run.wait()
47         else:
48             logg.debug("output from %s: %s", cwd and cwd+"/" or "shell", sh_command)
49             run = subprocess.Popen(command, shell=shell, cwd=cwd,
50                 stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=None, env=env)
51             if run.returncode:
52                 logg.warning("EXIT %s: %s", run.returncode, command)
53             output, errors = run.communicate() # run.wait()
54     except:
55         logg.error("*E*: %s", sh_command)
56         for line in output.split("\n"):
57             if line:
58                 logg.error("OUT: %s", line)
59         for line in errors.split("\n"):
60             if line:
61                 logg.error("ERR: %s", line)
62         raise
63     if run.returncode not in returncodes:
64         logg.warning("*%02i: %s", run.returncode, sh_command)
65         for line in output.split("\n"):
66             if line:
67                 logg.warning("OUT: %s", line)
68         for line in errors.split("\n"):
69             if line:
70                 logg.warning("ERR: %s", line)
71         raise subprocess.CalledProcessError(run.returncode, sh_command, output)
72     else:
73         for line in output.split("\n"):
74             if line:
75                 logg.debug("OUT: %s", line)
76         for line in errors.split("\n"):
77             if line:
78                 logg.debug("ERR: %s", line)
79     return Shell(run.returncode, output, errors, sh_command)
80
81 def testdir(testname):
82     newdir = "tests/tmp."+testname
83     if os.path.isdir(newdir):
84         shutil.rmtree(newdir)
85     os.makedirs(newdir)
86     return newdir
87
88 def download(base_url, filename, into):
89     if not os.path.isdir(into):
90         os.makedirs(into)
91     if not os.path.exists(os.path.join(into, filename)):
92         shell("cd {into} && wget {base_url}/{filename}".format(**locals()))
93 def trycopy(srcdir, filename, into):
94     if not os.path.isdir(into):
95         os.makedirs(into)
96     src_file = os.path.join(srcdir, filename)
97     dst_file = os.path.join(into, filename)
98     if os.path.isfile(src_file):
99         shutil.copy(src_file, dst_file)
100
101 def output(cmd, shell=True):
102     run = subprocess.Popen(cmd, shell=shell, stdout=subprocess.PIPE)
103     out, err = run.communicate()
104     return out
105 def grep(pattern, lines):
106     if isinstance(lines, basestring):
107         lines = lines.split("\n")
108     for line in lines:
109        if re.search(pattern, line.rstrip()):
110            yield line.rstrip()
111 def greps(lines, pattern):
112     return list(grep(pattern, lines))
113
114
115 class ZZipTest(unittest.TestCase):
116   @property
117   def t(self):
118     if not os.path.isdir(testdatadir):
119        os.makedirs(testdatadir)
120     return testdatdir
121   @property
122   def s(self):
123     return topsrcdir
124   def src(self, name):
125     return os.path.join(self.s, name)
126   def readme(self):
127      f = open(self.src(readme))
128      text = f.read()
129      f.close()
130      return text
131   def mkfile(self, name, content):
132     b = os.path.dirname(name)
133     if not os.path.isdir(b):
134        os.makedirs(b)
135     f = open(name, "w")
136     f.write(content)
137     f.close()
138   def bins(self, name):
139     if name == "unzip": return unzip
140     if name == "mkzip": return mkzip
141     exe = os.path.join("..", "bins", name)
142     if exeext: exe += exeext
143     return exe
144   def gentext(self, size):
145     random.seed(1234567891234567890)
146     result = StringIO()
147     old1 = ''
148     old2 = ''
149     for i in xrange(size):
150        while True:
151           x = random.choice("       abcdefghijklmnopqrstuvwxyz\n")
152           if x == old1 or x == old2: continue
153           old1 = old2
154           old2 = x
155           break
156        result.write(x)
157     return result.getvalue()
158   ################################################################
159   def test_100_make_test0_zip(self):
160     """ create a test.zip for later tests using standard 'zip'
161     It will fall back to a variant in the source code if 'zip'
162     is not installed on the build host. The content is just
163     the README file that we can check for equality later on. """
164     zipfile="test0.zip"
165     tmpdir="test0.tmp"
166     exe=self.bins("mkzip")
167     filename = os.path.join(tmpdir,"README")
168     filetext = self.readme()
169     self.mkfile(filename, filetext)
170     shell("{exe} ../{zipfile} README".format(**locals()), cwd=tmpdir)
171     self.assertGreater(os.path.getsize(zipfile), 10)
172   def test_101_make_test1_zip(self):
173     """ create a test1.zip for later tests using standard 'zip'
174     It will fall back to a variant in the source code if 'zip'
175     is not installed on the build host. The archive has 10
176     generic files that we can check for their content later. """
177     zipfile="test1.zip"
178     tmpdir="test1.tmp"
179     exe=self.bins("mkzip")
180     for i in [1,2,3,4,5,6,7,8,9]:
181        filename = os.path.join(tmpdir,"file.%i" % i)
182        filetext = "file-%i\n" % i
183        self.mkfile(filename, filetext)
184     filename = os.path.join(tmpdir,"README")
185     filetext = self.readme()
186     self.mkfile(filename, filetext)
187     shell("{exe} ../{zipfile} ??*.* README".format(**locals()), cwd=tmpdir)
188     self.assertGreater(os.path.getsize(zipfile), 10)
189   def test_102_make_test2_zip(self):
190     """ create a test2.zip for later tests using standard 'zip'
191     It will NOT fall back to a variant in the source code.
192     The archive has 100 generic files with known content. """
193     zipfile="test2.zip"
194     tmpdir="test2.tmp"
195     exe=self.bins("mkzip")
196     for i in xrange(100):
197        filename = os.path.join(tmpdir,"file.%02i" % i)
198        filetext = "file-%02i\n" % i
199        self.mkfile(filename, filetext)
200     filename = os.path.join(tmpdir,"README")
201     filetext = self.readme()
202     self.mkfile(filename, filetext)
203     shell("{exe} ../{zipfile} ??*.* README".format(**locals()), cwd=tmpdir)
204     self.assertGreater(os.path.getsize(zipfile), 10)
205   def test_103_make_test3_zip(self):
206     """ create a test3.zip for later tests using standard 'zip'
207     It will NOT fall back to a variant in the source code.
208     The archive has 1000 generic files with known content. """
209     zipfile="test3.zip"
210     tmpdir="test3.tmp"
211     exe=self.bins("mkzip")
212     for i in xrange(1000):
213        filename = os.path.join(tmpdir,"file.%03i" % i)
214        filetext = "file-%03i\n" % i
215        self.mkfile(filename, filetext)
216     filename = os.path.join(tmpdir,"README")
217     filetext = self.readme()
218     self.mkfile(filename, filetext)
219     shell("{exe} ../{zipfile} ??*.* README".format(**locals()), cwd=tmpdir)
220     self.assertGreater(os.path.getsize(zipfile), 10)
221   def test_104_make_test4_zip(self):
222     """ create a test4.zip for later tests using standard 'zip'
223     It will NOT fall back to a variant in the source code.
224     The archive has 10000 generic files with known content
225     and they are stored (NOT compressed) in the archive. """
226     zipfile="test4.zip"
227     tmpdir="test4.tmp"
228     exe=self.bins("mkzip")
229     for i in xrange(10000):
230        filename = os.path.join(tmpdir,"file%04i.txt" % i)
231        filetext = "file-%04i\n" % i
232        self.mkfile(filename, filetext)
233     filename = os.path.join(tmpdir,"README")
234     filetext = self.readme()
235     self.mkfile(filename, filetext)
236     shell("{exe} -n README ../{zipfile} ??*.* README".format(**locals()), cwd=tmpdir)
237     self.assertGreater(os.path.getsize(zipfile), 1000000)
238   def test_105_make_test5_zip(self):
239     """ create a test5.zip for later tests using standard 'zip'
240     It will NOT fall back to a variant in the source code.
241     The archive has files at multiple subdirectories depth
242     and of varying sizes each. """
243     zipfile="test5.zip"
244     tmpdir="test5.tmp"
245     exe=self.bins("mkzip")
246     for depth in xrange(20):
247       dirpath = ""
248       for i in xrange(depth):
249         if i:
250           dirpath += "subdir%i/" % i
251       for size in xrange(18):
252         size = 2 ** size
253         filetext = self.gentext(size)
254         filepart = "file%i-%i.txt" % (depth, size)
255         filename = os.path.join(tmpdir, dirpath + filepart )
256         self.mkfile(filename, filetext)
257     filename = os.path.join(tmpdir,"README")
258     filetext = self.readme()
259     self.mkfile(filename, filetext)
260     shell("{exe} ../{zipfile} -r file* subdir* README".format(**locals()), cwd=tmpdir)
261     self.assertGreater(os.path.getsize(zipfile), 1000000)
262   def test_110_make_test0_dat(self):
263     """ create test.dat from test.zip with xorcopy """
264     zipfile = "test0.zip"
265     datfile = "test0x.dat"
266     exe = self.bins("zzxorcopy")
267     shell("{exe} {zipfile} {datfile}".format(**locals()))
268     self.assertGreater(os.path.getsize(datfile), 10)
269     self.assertEqual(os.path.getsize(datfile), os.path.getsize(zipfile))
270   def test_111_make_test1_dat(self):
271     """ create test.dat from test.zip with xorcopy """
272     zipfile = "test1.zip"
273     datfile = "test1x.dat"
274     exe = self.bins("zzxorcopy")
275     shell("{exe} {zipfile} {datfile}".format(**locals()))
276     self.assertGreater(os.path.getsize(datfile), 10)
277     self.assertEqual(os.path.getsize(datfile), os.path.getsize(zipfile))
278   def test_112_make_test2_dat(self):
279     """ create test.dat from test.zip with xorcopy """
280     zipfile = "test2.zip"
281     datfile = "test2x.dat"
282     exe = self.bins("zzxorcopy")
283     shell("{exe} {zipfile} {datfile}".format(**locals()))
284     self.assertGreater(os.path.getsize(datfile), 10)
285     self.assertEqual(os.path.getsize(datfile), os.path.getsize(zipfile))
286   def test_113_make_test3_dat(self):
287     """ create test.dat from test.zip with xorcopy """
288     zipfile = "test3.zip"
289     datfile = "test3x.dat"
290     exe = self.bins("zzxorcopy")
291     shell("{exe} {zipfile} {datfile}".format(**locals()))
292     self.assertGreater(os.path.getsize(datfile), 10)
293     self.assertEqual(os.path.getsize(datfile), os.path.getsize(zipfile))
294   def test_114_make_test4_dat(self):
295     """ create test.dat from test.zip with xorcopy """
296     zipfile = "test4.zip"
297     datfile = "test4x.dat"
298     exe = self.bins("zzxorcopy")
299     shell("{exe} {zipfile} {datfile}".format(**locals()))
300     self.assertGreater(os.path.getsize(datfile), 10)
301     self.assertEqual(os.path.getsize(datfile), os.path.getsize(zipfile))
302   def test_200_zziptest_test0_zip(self):
303     """ run zziptest on test.zip """
304     zipfile = "test0.zip"
305     logfile = "test0.log"
306     exe = self.bins("zziptest")
307     shell("{exe} --quick {zipfile} | tee {logfile}".format(**locals()))
308     self.assertGreater(os.path.getsize(logfile), 10)
309   def test_201_zziptest_test1_zip(self):
310     """ run zziptest on test.zip """
311     zipfile = "test1.zip"
312     logfile = "test1.log"
313     exe = self.bins("zziptest")
314     shell("{exe} --quick {zipfile} | tee {logfile}".format(**locals()))
315     self.assertGreater(os.path.getsize(logfile), 10)
316   def test_202_zziptest_test2_zip(self):
317     """ run zziptest on test.zip """
318     zipfile = "test2.zip"
319     logfile = "test2.log"
320     exe = self.bins("zziptest")
321     shell("{exe} --quick {zipfile} | tee {logfile}".format(**locals()))
322     self.assertGreater(os.path.getsize(logfile), 10)
323   def test_203_zziptest_test3_zip(self):
324     """ run zziptest on test.zip """
325     zipfile = "test3.zip"
326     logfile = "test3.log"
327     exe = self.bins("zziptest")
328     shell("{exe} --quick {zipfile} | tee {logfile}".format(**locals()))
329     self.assertGreater(os.path.getsize(logfile), 10)
330   def test_204_zziptest_test4_zip(self):
331     """ run zziptest on test.zip """
332     zipfile = "test4.zip"
333     logfile = "test4.log"
334     exe = self.bins("zziptest")
335     shell("{exe} --quick {zipfile} | tee {logfile}".format(**locals()))
336     self.assertGreater(os.path.getsize(logfile), 10)
337   def test_210_zzcat_test0_zip(self):
338     """ run zzcat on test.zip using just test/README """
339     zipfile = "test0.zip"
340     getfile = "test0/README"
341     logfile = "test0.readme.txt"
342     exe = self.bins("zzcat")
343     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
344     self.assertGreater(os.path.getsize(logfile), 10)
345     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
346   def test_211_zzcat_test1_zip(self):
347     """ run zzcat on test.zip using just test/README """
348     zipfile = "test1.zip"
349     getfile = "test1/README"
350     logfile = "test1.readme.txt"
351     exe = self.bins("zzcat")
352     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
353     self.assertGreater(os.path.getsize(logfile), 10)
354     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
355     getfile = "test1/file.1"
356     run = shell("{exe} {getfile}".format(**locals()))
357     self.assertEqual("file-1\n", run.output)
358   def test_212_zzcat_test2_zip(self):
359     """ run zzcat on test.zip using just test/README """
360     zipfile = "test2.zip"
361     getfile = "test2/README"
362     logfile = "test2.readme.txt"
363     exe = self.bins("zzcat")
364     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
365     self.assertGreater(os.path.getsize(logfile), 10)
366     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
367     getfile = "test2/file.22"
368     run = shell("{exe} {getfile}".format(**locals()))
369     self.assertEqual("file-22\n", run.output)
370   def test_213_zzcat_test3_zip(self):
371     """ run zzcat on test.zip using just test/README """
372     zipfile = "test3.zip"
373     getfile = "test3/README"
374     logfile = "test3.readme.txt"
375     exe = self.bins("zzcat")
376     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
377     self.assertGreater(os.path.getsize(logfile), 10)
378     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
379     getfile = "test3/file.999"
380     run = shell("{exe} {getfile}".format(**locals()))
381     self.assertEqual("file-999\n", run.output)
382   def test_214_zzcat_test4_zip(self):
383     """ run zzcat on test.zip using just test/README """
384     zipfile = "test4.zip"
385     getfile = "test4/README"
386     logfile = "test4.readme.txt"
387     exe = self.bins("zzcat")
388     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
389     self.assertGreater(os.path.getsize(logfile), 10)
390     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
391     getfile = "test4/file9999.txt"
392     run = shell("{exe} {getfile}".format(**locals()))
393     self.assertEqual("file-9999\n", run.output)
394   def test_220_zzdir_test0_zip(self):
395     """ run zzdir on test0.zip using just 'test0' """
396     zipfile = "test0.zip"
397     getfile = "test0"
398     exe = self.bins("zzdir")
399     run = shell("{exe} {getfile} ".format(**locals()))
400     self.assertIn(' README\n', run.output)
401     self.assertIn(' defl:N ', run.output)
402     self.assertLess(len(run.output), 30)
403   def test_221_zzdir_test1_zip(self):
404     """ run zzdir on test1.zip using just 'test1' """
405     zipfile = "test1.zip"
406     getfile = "test1"
407     exe = self.bins("zzdir")
408     run = shell("{exe} {getfile} ".format(**locals()))
409     self.assertIn(' file.1\n', run.output)
410     self.assertIn(' file.2\n', run.output)
411     self.assertIn(' file.9\n', run.output)
412     self.assertIn(' README\n', run.output)
413     self.assertIn(' defl:N ', run.output)
414     self.assertIn(' stored ', run.output)
415   def test_222_zzdir_test2_zip(self):
416     """ run zzdir on test2.zip using just 'test2' """
417     zipfile = "test2.zip"
418     getfile = "test2"
419     exe = self.bins("zzdir")
420     run = shell("{exe} {getfile} ".format(**locals()))
421     self.assertIn(' file.01\n', run.output)
422     self.assertIn(' file.22\n', run.output)
423     self.assertIn(' file.99\n', run.output)
424     self.assertIn(' defl:N ', run.output)
425     self.assertIn(' stored ', run.output)
426   def test_223_zzdir_test3_zip(self):
427     """ run zzdir on test3.zip using just 'test3' """
428     zipfile = "test3.zip"
429     getfile = "test3"
430     exe = self.bins("zzdir")
431     run = shell("{exe} {getfile} ".format(**locals()))
432     self.assertIn(' file.001\n', run.output)
433     self.assertIn(' file.222\n', run.output)
434     self.assertIn(' file.999\n', run.output)
435     self.assertIn(' defl:N ', run.output)
436     self.assertIn(' stored ', run.output)
437   def test_224_zzdir_test4_zip(self):
438     """ run zzdir on test4.zip using just 'test4' """
439     zipfile = "test4.zip"
440     getfile = "test4"
441     exe = self.bins("zzdir")
442     run = shell("{exe} {getfile} ".format(**locals()))
443     self.assertIn(' file0001.txt\n', run.output)
444     self.assertIn(' file2222.txt\n', run.output)
445     self.assertIn(' file9999.txt\n', run.output)
446     self.assertNotIn(' defl:N ', run.output)
447     self.assertIn(' stored ', run.output)
448   def test_320_zzxordir_test0_dat(self):
449     """ run zzxordir on test0x.dat """
450     zipfile = "test0x.dat"
451     getfile = "test0x.dat"
452     exe = self.bins("zzdir")
453     run = shell("{exe} {getfile} ".format(**locals()), returncodes = [0,1])
454     self.assertEqual(run.returncode, 1)
455     self.assertEqual("", run.output)
456     self.assertIn("did not open test", run.errors)
457     exe = self.bins("zzxordir")
458     run = shell("{exe} {getfile} ".format(**locals()))
459     self.assertIn(' README\n', run.output)
460     self.assertIn(' defl:N ', run.output)
461     self.assertLess(len(run.output), 30)
462   def test_321_zzxordir_test1_dat(self):
463     """ run zzxordir on test1x.dat using just 'test1x' """
464     zipfile = "test1x.dat"
465     getfile = "test1x.dat"
466     exe = self.bins("zzdir")
467     run = shell("{exe} {getfile} ".format(**locals()), returncodes = [0,1])
468     self.assertEqual(run.returncode, 1)
469     self.assertEqual("", run.output)
470     self.assertIn("did not open test", run.errors)
471     exe = self.bins("zzxordir")
472     run = shell("{exe} {getfile} ".format(**locals()))
473     self.assertIn(' file.1\n', run.output)
474     self.assertIn(' file.2\n', run.output)
475     self.assertIn(' file.9\n', run.output)
476     self.assertIn(' README\n', run.output)
477     self.assertIn(' defl:N ', run.output)
478     self.assertIn(' stored ', run.output)
479   def test_322_zzxordir_test2_dat(self):
480     """ run zzxordir on test2x.dat using just 'test2x' """
481     zipfile = "test2x.dat"
482     getfile = "test2x"
483     exe = self.bins("zzdir")
484     run = shell("{exe} {getfile} ".format(**locals()), returncodes = [0,1])
485     self.assertEqual(run.returncode, 1)
486     self.assertEqual("", run.output)
487     self.assertIn("did not open test", run.errors)
488     exe = self.bins("zzxordir")
489     run = shell("{exe} {getfile} ".format(**locals()))
490     self.assertIn(' file.01\n', run.output)
491     self.assertIn(' file.22\n', run.output)
492     self.assertIn(' file.99\n', run.output)
493     self.assertIn(' defl:N ', run.output)
494     self.assertIn(' stored ', run.output)
495   def test_323_zzxordir_test3_dat(self):
496     """ run zzxordir on test3x.dat using just 'test3x' """
497     zipfile = "test3x.dat"
498     getfile = "test3x"
499     exe = self.bins("zzdir")
500     run = shell("{exe} {getfile} ".format(**locals()), returncodes = [0,1])
501     self.assertEqual(run.returncode, 1)
502     self.assertEqual("", run.output)
503     self.assertIn("did not open test", run.errors)
504     exe = self.bins("zzxordir")
505     run = shell("{exe} {getfile} ".format(**locals()))
506     self.assertIn(' file.001\n', run.output)
507     self.assertIn(' file.222\n', run.output)
508     self.assertIn(' file.999\n', run.output)
509     self.assertIn(' defl:N ', run.output)
510     self.assertIn(' stored ', run.output)
511   def test_324_zzxordir_test4_zip(self):
512     """ run zzxordir on test4x.dat using just 'test4x' """
513     zipfile = "test4x.dat"
514     getfile = "test4x"
515     exe = self.bins("zzdir")
516     run = shell("{exe} {getfile} ".format(**locals()), returncodes = [0,1])
517     self.assertEqual(run.returncode, 1)
518     self.assertEqual("", run.output)
519     self.assertIn("did not open test", run.errors)
520     exe = self.bins("zzxordir")
521     run = shell("{exe} {getfile} ".format(**locals()))
522     self.assertIn(' file0001.txt\n', run.output)
523     self.assertIn(' file2222.txt\n', run.output)
524     self.assertIn(' file9999.txt\n', run.output)
525     self.assertNotIn(' defl:N ', run.output)
526     self.assertIn(' stored ', run.output)
527   def test_340_zzxorcat_test0_zip(self):
528     """ run zzxorcat on testx.zip using just testx/README """
529     getfile = "test0x/README"
530     logfile = "test0x.readme.txt"
531     exe = self.bins("zzcat")
532     run = shell("{exe} {getfile} ".format(**locals()), lang="C")
533     self.assertEqual("", run.output)
534     self.assertIn("No such file or directory", run.errors)
535     exe = self.bins("zzxorcat")
536     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
537     self.assertGreater(os.path.getsize(logfile), 10)
538     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
539   def test_341_zzxorcat_test1_zip(self):
540     """ run zzxorcat on testx.zip using just testx/README """
541     getfile = "test1x/README"
542     logfile = "test1x.readme.txt"
543     exe = self.bins("zzcat")
544     run = shell("{exe} {getfile} ".format(**locals()), lang="C")
545     self.assertEqual("", run.output)
546     self.assertIn("No such file or directory", run.errors)
547     exe = self.bins("zzxorcat")
548     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
549     self.assertGreater(os.path.getsize(logfile), 10)
550     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
551     getfile = "test1x/file.1"
552     run = shell("{exe} {getfile}".format(**locals()))
553     self.assertEqual("file-1\n", run.output)
554   def test_342_zzxorcat_test2_zip(self):
555     """ run zzxorcat on testx.zip using just testx/README """
556     getfile = "test2x/README"
557     logfile = "test2x.readme.txt"
558     exe = self.bins("zzcat")
559     run = shell("{exe} {getfile} ".format(**locals()), lang="C")
560     self.assertEqual("", run.output)
561     self.assertIn("No such file or directory", run.errors)
562     exe = self.bins("zzxorcat")
563     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
564     self.assertGreater(os.path.getsize(logfile), 10)
565     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
566     getfile = "test2x/file.22"
567     run = shell("{exe} {getfile}".format(**locals()))
568     self.assertEqual("file-22\n", run.output)
569   def test_343_zzxorcat_test3_zip(self):
570     """ run zzxorcat on testx.zip using just testx/README """
571     getfile = "test3x/README"
572     logfile = "test3x.readme.txt"
573     exe = self.bins("zzcat")
574     run = shell("{exe} {getfile} ".format(**locals()), lang="C")
575     self.assertEqual("", run.output)
576     self.assertIn("No such file or directory", run.errors)
577     exe = self.bins("zzxorcat")
578     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
579     self.assertGreater(os.path.getsize(logfile), 10)
580     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
581     getfile = "test3x/file.999"
582     run = shell("{exe} {getfile}".format(**locals()))
583     self.assertEqual("file-999\n", run.output)
584   def test_344_zzxorcat_test4_zip(self):
585     """ run zzxorcat on testx.zip using just testx/README """
586     getfile = "test4x/README"
587     logfile = "test4x.readme.txt"
588     exe = self.bins("zzxorcat")
589     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
590     self.assertGreater(os.path.getsize(logfile), 10)
591     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
592     getfile = "test4x/file9999.txt"
593     run = shell("{exe} {getfile}".format(**locals()))
594     self.assertEqual("file-9999\n", run.output)
595   #####################################################################
596   # check unzzip
597   #####################################################################
598   def test_400_infozip_cat_test0_zip(self):
599     """ run inzo-zip cat test.zip using just archive README """
600     zipfile = "test0.zip"
601     getfile = "README"
602     logfile = "test0.readme.pk.txt"
603     exe = self.bins("unzip")
604     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
605     self.assertGreater(os.path.getsize(logfile), 10)
606     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
607   def test_401_infozip_cat_test1_zip(self):
608     """ run info-zip cat test.zip using just archive README """
609     zipfile = "test1.zip"
610     getfile = "README"
611     logfile = "test1.readme.pk.txt"
612     exe = self.bins("unzip")
613     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
614     self.assertGreater(os.path.getsize(logfile), 10)
615     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
616     getfile = "file.1"
617     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
618     self.assertEqual("file-1\n", run.output)
619   def test_402_infozip_cat_test2_zip(self):
620     """ run info-zip cat test.zip using just archive README """
621     zipfile = "test2.zip"
622     getfile = "README"
623     logfile = "test2.readme.pk.txt"
624     exe = self.bins("unzip")
625     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
626     self.assertGreater(os.path.getsize(logfile), 10)
627     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
628     getfile = "file.22"
629     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
630     self.assertEqual("file-22\n", run.output)
631   def test_405_zzcat_big_test5_zip(self):
632     """ run info-zip cat test.zip using archive README """
633     zipfile = "test5.zip"
634     getfile = "README"
635     logfile = "test5.readme.pk.txt"
636     exe = self.bins("unzip")
637     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
638     self.assertGreater(os.path.getsize(logfile), 10)
639     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
640     getfile = "subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/file7-1024.txt"
641     compare = self.gentext(1024)
642     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
643     self.assertEqual(compare, run.output)
644   def test_410_zzcat_big_test0_zip(self):
645     """ run zzcat-big on test.zip using just archive README """
646     zipfile = "test0.zip"
647     getfile = "README"
648     logfile = "test0.readme.big.txt"
649     exe = self.bins("unzzip-big")
650     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
651     self.assertGreater(os.path.getsize(logfile), 10)
652     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
653   def test_411_zzcat_big_test1_zip(self):
654     """ run zzcat-big on test.zip using just archive README """
655     zipfile = "test1.zip"
656     getfile = "README"
657     logfile = "test1.readme.big.txt"
658     exe = self.bins("unzzip-big")
659     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
660     self.assertGreater(os.path.getsize(logfile), 10)
661     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
662     getfile = "file.1"
663     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
664     self.assertEqual("file-1\n", run.output)
665   def test_412_zzcat_big_test2_zip(self):
666     """ run zzcat-seeke on test.zip using just archive README """
667     zipfile = "test2.zip"
668     getfile = "README"
669     logfile = "test2.readme.big.txt"
670     exe = self.bins("unzzip-big")
671     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
672     self.assertGreater(os.path.getsize(logfile), 10)
673     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
674     getfile = "file.22"
675     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
676     self.assertEqual("file-22\n", run.output)
677   def test_415_zzcat_big_test5_zip(self):
678     """ run zzcat-big on test.zip using archive README """
679     zipfile = "test5.zip"
680     getfile = "README"
681     logfile = "test5.readme.zap.txt"
682     exe = self.bins("unzzip-big")
683     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
684     self.assertGreater(os.path.getsize(logfile), 10)
685     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
686     getfile = "subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/file7-1024.txt"
687     compare = self.gentext(1024)
688     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
689     self.assertEqual(compare, run.output)
690   def test_420_zzcat_mem_test0_zip(self):
691     """ run zzcat-mem on test.zip using just archive README """
692     zipfile = "test0.zip"
693     getfile = "README"
694     logfile = "test0.readme.mem.txt"
695     exe = self.bins("unzzip-mem")
696     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
697     self.assertGreater(os.path.getsize(logfile), 10)
698     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
699   def test_421_zzcat_mem_test1_zip(self):
700     """ run zzcat-mem on test.zip using archive README """
701     zipfile = "test1.zip"
702     getfile = "README"
703     logfile = "test1.readme.mem.txt"
704     exe = self.bins("unzzip-mem")
705     run = shell("{exe} -p {zipfile}  {getfile} | tee {logfile}".format(**locals()))
706     self.assertGreater(os.path.getsize(logfile), 10)
707     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
708     getfile = "file.1"
709     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
710     self.assertEqual("file-1\n", run.output)
711   def test_422_zzcat_mem_test2_zip(self):
712     """ run zzcat-mem on test.zip using archive README """
713     zipfile = "test2.zip"
714     getfile = "README"
715     logfile = "test2.readme.mem.txt"
716     exe = self.bins("unzzip-mem")
717     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
718     self.assertGreater(os.path.getsize(logfile), 10)
719     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
720     getfile = "file.22"
721     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
722     self.assertEqual("file-22\n", run.output)
723   def test_423_zzcat_mem_test3_zip(self):
724     """ run zzcat-mem on test.zip using archive README """
725     zipfile = "test3.zip"
726     getfile = "README"
727     logfile = "test3.readme.mem.txt"
728     exe = self.bins("unzzip-mem")
729     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
730     self.assertGreater(os.path.getsize(logfile), 10)
731     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
732     getfile = "file.999"
733     run = shell("{exe} -p {zipfile}  {getfile}".format(**locals()))
734     self.assertEqual("file-999\n", run.output)
735   def test_424_zzcat_mem_test4_zip(self):
736     """ run zzcat-mem on test.zip using archive README """
737     zipfile = "test4.zip"
738     getfile = "README"
739     logfile = "test4.readme.mem.txt"
740     exe = self.bins("unzzip-mem")
741     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
742     self.assertGreater(os.path.getsize(logfile), 10)
743     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
744     getfile = "file9999.txt"
745     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
746     self.assertEqual("file-9999\n", run.output)
747   def test_425_zzcat_mem_test5_zip(self):
748     """ run zzcat-mem on test.zip using archive README """
749     zipfile = "test5.zip"
750     getfile = "README"
751     logfile = "test5.readme.zap.txt"
752     exe = self.bins("unzzip-mem")
753     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
754     self.assertGreater(os.path.getsize(logfile), 10)
755     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
756     getfile = "subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/file7-1024.txt"
757     compare = self.gentext(1024)
758     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
759     self.assertEqual(compare, run.output)
760   def test_430_zzcat_mix_test0_zip(self):
761     """ run zzcat-mix on test.zip using just archive README """
762     zipfile = "test0.zip"
763     getfile = "README"
764     logfile = "test0.readme.mix.txt"
765     exe = self.bins("unzzip-mix")
766     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
767     self.assertGreater(os.path.getsize(logfile), 10)
768     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
769   def test_431_zzcat_mix_test1_zip(self):
770     """ run zzcat-mix on test.zip using archive README """
771     zipfile = "test1.zip"
772     getfile = "README"
773     logfile = "test1.readme.mix.txt"
774     exe = self.bins("unzzip-mix")
775     run = shell("{exe} -p {zipfile}  {getfile} | tee {logfile}".format(**locals()))
776     self.assertGreater(os.path.getsize(logfile), 10)
777     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
778     getfile = "file.1"
779     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
780     self.assertEqual("file-1\n", run.output)
781   def test_432_zzcat_mix_test2_zip(self):
782     """ run zzcat-mix on test.zip using archive README """
783     zipfile = "test2.zip"
784     getfile = "README"
785     logfile = "test2.readme.mix.txt"
786     exe = self.bins("unzzip-mix")
787     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
788     self.assertGreater(os.path.getsize(logfile), 10)
789     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
790     getfile = "file.22"
791     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
792     self.assertEqual("file-22\n", run.output)
793   def test_433_zzcat_mix_test3_zip(self):
794     """ run zzcat-mix on test.zip using archive README """
795     zipfile = "test3.zip"
796     getfile = "README"
797     logfile = "test3.readme.mix.txt"
798     exe = self.bins("unzzip-mix")
799     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
800     self.assertGreater(os.path.getsize(logfile), 10)
801     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
802     getfile = "file.999"
803     run = shell("{exe} -p {zipfile}  {getfile}".format(**locals()))
804     self.assertEqual("file-999\n", run.output)
805   def test_434_zzcat_mix_test4_zip(self):
806     """ run zzcat-mix on test.zip using archive README """
807     zipfile = "test4.zip"
808     getfile = "README"
809     logfile = "test4.readme.mix.txt"
810     exe = self.bins("unzzip-mix")
811     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
812     self.assertGreater(os.path.getsize(logfile), 10)
813     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
814     getfile = "file9999.txt"
815     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
816     self.assertEqual("file-9999\n", run.output)
817   def test_435_zzcat_mix_test5_zip(self):
818     """ run zzcat-mix on test.zip using archive README """
819     zipfile = "test5.zip"
820     getfile = "README"
821     logfile = "test5.readme.zap.txt"
822     exe = self.bins("unzzip-mix")
823     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
824     self.assertGreater(os.path.getsize(logfile), 10)
825     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
826     getfile = "subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/file7-1024.txt"
827     compare = self.gentext(1024)
828     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
829     self.assertEqual(compare, run.output)
830   def test_440_zzcat_zap_test0_zip(self):
831     """ run zzcat-zap on test.zip using just archive README """
832     zipfile = "test0.zip"
833     getfile = "README"
834     logfile = "test0.readme.txt"
835     exe = self.bins("unzzip")
836     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
837     self.assertGreater(os.path.getsize(logfile), 10)
838     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
839   def test_441_zzcat_zap_test1_zip(self):
840     """ run zzcat-zap on test.zip using archive README """
841     zipfile = "test1.zip"
842     getfile = "README"
843     logfile = "test1.readme.zap.txt"
844     exe = self.bins("unzzip")
845     run = shell("{exe} -p {zipfile}  {getfile} | tee {logfile}".format(**locals()))
846     self.assertGreater(os.path.getsize(logfile), 10)
847     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
848     getfile = "file.1"
849     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
850     self.assertEqual("file-1\n", run.output)
851   def test_442_zzcat_zap_test2_zip(self):
852     """ run zzcat-zap on test.zip using archive README """
853     zipfile = "test2.zip"
854     getfile = "README"
855     logfile = "test2.readme.zap.txt"
856     exe = self.bins("unzzip")
857     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
858     self.assertGreater(os.path.getsize(logfile), 10)
859     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
860     getfile = "file.22"
861     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
862     self.assertEqual("file-22\n", run.output)
863   def test_443_zzcat_zap_test3_zip(self):
864     """ run zzcat-zap on test.zip using archive README """
865     zipfile = "test3.zip"
866     getfile = "README"
867     logfile = "test3.readme.zap.txt"
868     exe = self.bins("unzzip")
869     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
870     self.assertGreater(os.path.getsize(logfile), 10)
871     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
872     getfile = "file.999"
873     run = shell("{exe} -p {zipfile}  {getfile}".format(**locals()))
874     self.assertEqual("file-999\n", run.output)
875   def test_444_zzcat_zap_test4_zip(self):
876     """ run zzcat-zap on test.zip using archive README """
877     zipfile = "test4.zip"
878     getfile = "README"
879     logfile = "test4.readme.zap.txt"
880     exe = self.bins("unzzip")
881     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
882     self.assertGreater(os.path.getsize(logfile), 10)
883     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
884     getfile = "file9999.txt"
885     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
886     self.assertEqual("file-9999\n", run.output)
887   def test_445_zzcat_zap_test5_zip(self):
888     """ run zzcat-zap on test.zip using archive README """
889     zipfile = "test5.zip"
890     getfile = "README"
891     logfile = "test5.readme.zap.txt"
892     exe = self.bins("unzzip")
893     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
894     self.assertGreater(os.path.getsize(logfile), 10)
895     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
896     getfile = "subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/file7-1024.txt"
897     compare = self.gentext(1024)
898     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
899     self.assertEqual(compare, run.output)
900
901   def test_500_infozipdir_test0_zip(self):
902     """ run info-zip dir test0.zip  """
903     zipfile = "test0.zip"
904     getfile = "test0.zip"
905     exe = self.bins("unzip")
906     run = shell("{exe} -l {getfile} ".format(**locals()))
907     self.assertIn(' README\n', run.output)
908     self.assertLess(len(run.output), 230)
909   def test_501_infozipdir_test1_zip(self):
910     """ run info-zip dir test1.zip  """
911     zipfile = "test1.zip"
912     getfile = "test1.zip"
913     exe = self.bins("unzip")
914     run = shell("{exe} -l {getfile} ".format(**locals()))
915     self.assertIn(' file.1\n', run.output)
916     self.assertIn(' file.2\n', run.output)
917     self.assertIn(' file.9\n', run.output)
918     self.assertIn(' README\n', run.output)
919   def test_502_infozipdir_big_test2_zip(self):
920     """ run info-zip dir test2.zip """
921     zipfile = "test2.zip"
922     getfile = "test2.zip"
923     exe = self.bins("unzip")
924     run = shell("{exe} -l {getfile} ".format(**locals()))
925     self.assertIn(' file.01\n', run.output)
926     self.assertIn(' file.22\n', run.output)
927     self.assertIn(' file.99\n', run.output)
928   def test_503_infozipdir_big_test3_zip(self):
929     """ run info-zip dir test3.zip  """
930     zipfile = "test3.zip"
931     getfile = "test3.zip"
932     exe = self.bins("unzip")
933     run = shell("{exe} -l {getfile} ".format(**locals()))
934     self.assertIn(' file.001\n', run.output)
935     self.assertIn(' file.222\n', run.output)
936     self.assertIn(' file.999\n', run.output)
937   def test_504_infozipdir_big_test4_zip(self):
938     """ run info-zip dir test4.zip """
939     zipfile = "test4.zip"
940     getfile = "test4.zip"
941     exe = self.bins("unzip")
942     run = shell("{exe} -l {getfile} ".format(**locals()))
943     self.assertIn(' file0001.txt\n', run.output)
944     self.assertIn(' file2222.txt\n', run.output)
945     self.assertIn(' file9999.txt\n', run.output)
946   def test_505_infozipdir_big_test5_zip(self):
947     """ run info-zip dir on test5.zip """
948     zipfile = "test5.zip"
949     getfile = "test5.zip"
950     exe = self.bins("unzzip-mix")
951     run = shell("{exe} -v {getfile} ".format(**locals()))
952     self.assertIn('/subdir14/file15-128.txt\n', run.output)
953     self.assertIn('/subdir5/subdir6/', run.output)
954     self.assertIn(' defl:N ', run.output)
955     self.assertIn(' stored ', run.output)
956   def test_510_zzdir_big_test0_zip(self):
957     """ run zzdir-big on test0.zip  """
958     zipfile = "test0.zip"
959     getfile = "test0.zip"
960     exe = self.bins("unzzip-big")
961     run = shell("{exe} -l {getfile} ".format(**locals()))
962     self.assertIn(' README\n', run.output)
963     self.assertLess(len(run.output), 30)
964   def test_511_zzdir_big_test1_zip(self):
965     """ run zzdir-big on test1.zip  """
966     zipfile = "test1.zip"
967     getfile = "test1.zip"
968     exe = self.bins("unzzip-big")
969     run = shell("{exe} -l {getfile} ".format(**locals()))
970     self.assertIn(' file.1\n', run.output)
971     self.assertIn(' file.2\n', run.output)
972     self.assertIn(' file.9\n', run.output)
973     self.assertIn(' README\n', run.output)
974   def test_512_zzdir_big_test2_zip(self):
975     """ run zzdir-big on test2.zip """
976     zipfile = "test2.zip"
977     getfile = "test2.zip"
978     exe = self.bins("unzzip-big")
979     run = shell("{exe} -l {getfile} ".format(**locals()))
980     self.assertIn(' file.01\n', run.output)
981     self.assertIn(' file.22\n', run.output)
982     self.assertIn(' file.99\n', run.output)
983   def test_513_zzdir_big_test3_zip(self):
984     """ run zzdir-big on test3.zip  """
985     zipfile = "test3.zip"
986     getfile = "test3.zip"
987     exe = self.bins("unzzip-big")
988     run = shell("{exe} -l {getfile} ".format(**locals()))
989     self.assertIn(' file.001\n', run.output)
990     self.assertIn(' file.222\n', run.output)
991     self.assertIn(' file.999\n', run.output)
992   def test_514_zzdir_big_test4_zip(self):
993     """ run zzdir-big on test4.zip """
994     zipfile = "test4.zip"
995     getfile = "test4.zip"
996     exe = self.bins("unzzip-big")
997     run = shell("{exe} -l {getfile} ".format(**locals()))
998     self.assertIn(' file0001.txt\n', run.output)
999     self.assertIn(' file2222.txt\n', run.output)
1000     self.assertIn(' file9999.txt\n', run.output)
1001   def test_515_zzdir_big_test5_zip(self):
1002     """ run zzdir-big on test5.zip """
1003     zipfile = "test5.zip"
1004     getfile = "test5.zip"
1005     exe = self.bins("unzzip-mix")
1006     run = shell("{exe} -v {getfile} ".format(**locals()))
1007     self.assertIn('/subdir14/file15-128.txt\n', run.output)
1008     self.assertIn('/subdir5/subdir6/', run.output)
1009     self.assertIn(' defl:N ', run.output)
1010     self.assertIn(' stored ', run.output)
1011   def test_520_zzdir_mem_test0_zip(self):
1012     """ run zzdir-mem on test0.zip  """
1013     zipfile = "test0.zip"
1014     getfile = "test0.zip"
1015     exe = self.bins("unzzip-mem")
1016     run = shell("{exe} -v {getfile} ".format(**locals()))
1017     self.assertIn(' README\n', run.output)
1018     self.assertIn(' defl:N ', run.output)
1019     self.assertLess(len(run.output), 30)
1020   def test_521_zzdir_mem_test1_zip(self):
1021     """ run zzdir-mem on test1.zip  """
1022     zipfile = "test1.zip"
1023     getfile = "test1.zip"
1024     exe = self.bins("unzzip-mem")
1025     run = shell("{exe} -v {getfile} ".format(**locals()))
1026     self.assertIn(' file.1\n', run.output)
1027     self.assertIn(' file.2\n', run.output)
1028     self.assertIn(' file.9\n', run.output)
1029     self.assertIn(' README\n', run.output)
1030     self.assertIn(' defl:N ', run.output)
1031     self.assertIn(' stored ', run.output)
1032   def test_522_zzdir_mem_test2_zip(self):
1033     """ run zzdir-mem on test2.zip """
1034     zipfile = "test2.zip"
1035     getfile = "test2.zip"
1036     exe = self.bins("unzzip-mem")
1037     run = shell("{exe} -v {getfile} ".format(**locals()))
1038     self.assertIn(' file.01\n', run.output)
1039     self.assertIn(' file.22\n', run.output)
1040     self.assertIn(' file.99\n', run.output)
1041     self.assertIn(' defl:N ', run.output)
1042     self.assertIn(' stored ', run.output)
1043   def test_523_zzdir_mem_test3_zip(self):
1044     """ run zzdir-mem on test3.zip  """
1045     zipfile = "test3.zip"
1046     getfile = "test3.zip"
1047     exe = self.bins("unzzip-mem")
1048     run = shell("{exe} -v {getfile} ".format(**locals()))
1049     self.assertIn(' file.001\n', run.output)
1050     self.assertIn(' file.222\n', run.output)
1051     self.assertIn(' file.999\n', run.output)
1052     self.assertIn(' defl:N ', run.output)
1053     self.assertIn(' stored ', run.output)
1054   def test_524_zzdir_mem_test4_zip(self):
1055     """ run zzdir-mem on test4.zip """
1056     zipfile = "test4.zip"
1057     getfile = "test4.zip"
1058     exe = self.bins("unzzip-mem")
1059     run = shell("{exe} -v {getfile} ".format(**locals()))
1060     self.assertIn(' file0001.txt\n', run.output)
1061     self.assertIn(' file2222.txt\n', run.output)
1062     self.assertIn(' file9999.txt\n', run.output)
1063     self.assertNotIn(' defl:N ', run.output)
1064     self.assertIn(' stored ', run.output)
1065   def test_525_zzdir_mem_test5_zip(self):
1066     """ run zzdir-mem on test5.zip """
1067     zipfile = "test5.zip"
1068     getfile = "test5.zip"
1069     exe = self.bins("unzzip-mix")
1070     run = shell("{exe} -v {getfile} ".format(**locals()))
1071     self.assertIn('/subdir14/file15-128.txt\n', run.output)
1072     self.assertIn('/subdir5/subdir6/', run.output)
1073     self.assertIn(' defl:N ', run.output)
1074     self.assertIn(' stored ', run.output)
1075   def test_530_zzdir_mix_test0_zip(self):
1076     """ run zzdir-mix on test0.zip  """
1077     # self.skipTest("todo")
1078     zipfile = "test0.zip"
1079     getfile = "test0.zip"
1080     exe = self.bins("unzzip-mix")
1081     run = shell("{exe} -v {getfile} ".format(**locals()))
1082     self.assertIn(' README\n', run.output)
1083     self.assertIn(' defl:N ', run.output)
1084     self.assertLess(len(run.output), 30)
1085   def test_531_zzdir_mix_test1_zip(self):
1086     """ run zzdir-mix on test1.zip  """
1087     zipfile = "test1.zip"
1088     getfile = "test1.zip"
1089     exe = self.bins("unzzip-mix")
1090     run = shell("{exe} -v {getfile} ".format(**locals()))
1091     self.assertIn(' file.1\n', run.output)
1092     self.assertIn(' file.2\n', run.output)
1093     self.assertIn(' file.9\n', run.output)
1094     self.assertIn(' README\n', run.output)
1095     self.assertIn(' defl:N ', run.output)
1096     self.assertIn(' stored ', run.output)
1097   def test_532_zzdir_mix_test2_zip(self):
1098     """ run zzdir-mix on test2.zip """
1099     zipfile = "test2.zip"
1100     getfile = "test2.zip"
1101     exe = self.bins("unzzip-mix")
1102     run = shell("{exe} -v {getfile} ".format(**locals()))
1103     self.assertIn(' file.01\n', run.output)
1104     self.assertIn(' file.22\n', run.output)
1105     self.assertIn(' file.99\n', run.output)
1106     self.assertIn(' defl:N ', run.output)
1107     self.assertIn(' stored ', run.output)
1108   def test_533_zzdir_mix_test3_zip(self):
1109     """ run zzdir-mix on test3.zip  """
1110     zipfile = "test3.zip"
1111     getfile = "test3.zip"
1112     exe = self.bins("unzzip-mix")
1113     run = shell("{exe} -v {getfile} ".format(**locals()))
1114     self.assertIn(' file.001\n', run.output)
1115     self.assertIn(' file.222\n', run.output)
1116     self.assertIn(' file.999\n', run.output)
1117     self.assertIn(' defl:N ', run.output)
1118     self.assertIn(' stored ', run.output)
1119   def test_534_zzdir_mix_test4_zip(self):
1120     """ run zzdir-mix on test4.zip """
1121     zipfile = "test4.zip"
1122     getfile = "test4.zip"
1123     exe = self.bins("unzzip-mix")
1124     run = shell("{exe} -v {getfile} ".format(**locals()))
1125     self.assertIn(' file0001.txt\n', run.output)
1126     self.assertIn(' file2222.txt\n', run.output)
1127     self.assertIn(' file9999.txt\n', run.output)
1128     self.assertNotIn(' defl:N ', run.output)
1129     self.assertIn(' stored ', run.output)
1130   def test_535_zzdir_mix_test5_zip(self):
1131     """ run zzdir-mix on test5.zip """
1132     zipfile = "test5.zip"
1133     getfile = "test5.zip"
1134     exe = self.bins("unzzip-mix")
1135     run = shell("{exe} -v {getfile} ".format(**locals()))
1136     self.assertIn('/subdir14/file15-128.txt\n', run.output)
1137     self.assertIn('/subdir5/subdir6/', run.output)
1138     self.assertIn(' defl:N ', run.output)
1139     self.assertIn(' stored ', run.output)
1140   def test_540_zzdir_zap_test0_zip(self):
1141     """ run zzdir-zap on test0.zip  """
1142     zipfile = "test0.zip"
1143     getfile = "test0.zip"
1144     exe = self.bins("unzzip")
1145     run = shell("{exe} -v {getfile} ".format(**locals()))
1146     self.assertIn(' README\n', run.output)
1147     self.assertIn(' defl:N ', run.output)
1148     self.assertLess(len(run.output), 30)
1149   def test_541_zzdir_zap_test1_zip(self):
1150     """ run zzdir-zap on test1.zip  """
1151     zipfile = "test1.zip"
1152     getfile = "test1.zip"
1153     exe = self.bins("unzzip")
1154     run = shell("{exe} -v {getfile} ".format(**locals()))
1155     self.assertIn(' file.1\n', run.output)
1156     self.assertIn(' file.2\n', run.output)
1157     self.assertIn(' file.9\n', run.output)
1158     self.assertIn(' README\n', run.output)
1159     self.assertIn(' defl:N ', run.output)
1160     self.assertIn(' stored ', run.output)
1161   def test_542_zzdir_zap_test2_zip(self):
1162     """ run zzdir-zap on test2.zip """
1163     zipfile = "test2.zip"
1164     getfile = "test2.zip"
1165     exe = self.bins("unzzip")
1166     run = shell("{exe} -v {getfile} ".format(**locals()))
1167     self.assertIn(' file.01\n', run.output)
1168     self.assertIn(' file.22\n', run.output)
1169     self.assertIn(' file.99\n', run.output)
1170     self.assertIn(' defl:N ', run.output)
1171     self.assertIn(' stored ', run.output)
1172   def test_543_zzdir_zap_test3_zip(self):
1173     """ run zzdir-zap on test3.zip  """
1174     zipfile = "test3.zip"
1175     getfile = "test3.zip"
1176     exe = self.bins("unzzip")
1177     run = shell("{exe} -v {getfile} ".format(**locals()))
1178     self.assertIn(' file.001\n', run.output)
1179     self.assertIn(' file.222\n', run.output)
1180     self.assertIn(' file.999\n', run.output)
1181     self.assertIn(' defl:N ', run.output)
1182     self.assertIn(' stored ', run.output)
1183   def test_544_zzdir_zap_test4_zip(self):
1184     """ run zzdir-zap on test4.zip """
1185     zipfile = "test4.zip"
1186     getfile = "test4.zip"
1187     exe = self.bins("unzzip")
1188     run = shell("{exe} -v {getfile} ".format(**locals()))
1189     self.assertIn(' file0001.txt\n', run.output)
1190     self.assertIn(' file2222.txt\n', run.output)
1191     self.assertIn(' file9999.txt\n', run.output)
1192     self.assertNotIn(' defl:N ', run.output)
1193     self.assertIn(' stored ', run.output)
1194   def test_545_zzdir_zap_test5_zip(self):
1195     """ run zzdir-zap on test5.zip """
1196     zipfile = "test5.zip"
1197     getfile = "test5.zip"
1198     exe = self.bins("unzzip")
1199     run = shell("{exe} -v {getfile} ".format(**locals()))
1200     self.assertIn('/subdir14/file15-128.txt\n', run.output)
1201     self.assertIn('/subdir5/subdir6/', run.output)
1202     self.assertIn(' defl:N ', run.output)
1203     self.assertIn(' stored ', run.output)
1204   def test_595_zzextract_zap_test5_zip(self):
1205     """ run zzextract-zap on test5.zip 
1206         => coughs up a SEGFAULT in zzip_dir_close() ?!?"""
1207     zipfile = "test5.zip"
1208     getfile = "test5.zip"
1209     tmpdir = "tmp.test_595"
1210     testdir(tmpdir)
1211     exe = self.bins("unzzip")
1212     run = shell("cd {tmpdir} && ../{exe} ../{getfile} ".format(**locals()))
1213     self.assertTrue(tmpdir+'/subdir1/subdir2/file3-1024.txt')
1214
1215   url_CVE_2017_5977 = "https://raw.githubusercontent.com/asarubbo/poc/master/"
1216   zip_CVE_2017_5977 = "00153-zziplib-invalidread-zzip_mem_entry_extra_block"
1217   def test_600_infozipdir_CVE_2017_5977(self):
1218     """ run info-zip dir test0.zip  """
1219     tmpdir = "tmp.test_600"
1220     filename = self.zip_CVE_2017_5977
1221     file_url = self.url_CVE_2017_5977
1222     trycopy("tmp.test_601", filename, tmpdir)
1223     testdir(tmpdir)
1224     download(file_url, filename, tmpdir)
1225     exe = self.bins("unzip")
1226     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1227         returncodes = [0, 2])
1228     self.assertIn(" didn't find end-of-central-dir signature at end of central dir", run.errors)
1229     self.assertIn(" 2 extra bytes at beginning or within zipfile", run.errors)
1230     self.assertLess(len(run.output), 280)
1231   def test_601_zzipdir_big_CVE_2017_5977(self):
1232     """ run info-zip -l $(CVE_2017_5977).zip  """
1233     tmpdir = "tmp.test_601"
1234     filename = self.zip_CVE_2017_5977
1235     file_url = self.url_CVE_2017_5977
1236     testdir(tmpdir)
1237     trycopy("tmp.test_600", filename, tmpdir)
1238     trycopy("tmp.test_602", filename, tmpdir)
1239     download(file_url, filename, tmpdir)
1240     exe = self.bins("unzzip-big")
1241     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1242         returncodes = [0])
1243     self.assertLess(len(run.output), 30)
1244     self.assertLess(len(run.errors), 1)
1245     self.assertIn(" stored test", run.output)
1246   def test_602_zzipdir_mem_CVE_2017_5977(self):
1247     """ run unzzip-mem -l $(CVE_2017_5977).zip  """
1248     tmpdir = "tmp.test_602"
1249     filename = self.zip_CVE_2017_5977
1250     file_url = self.url_CVE_2017_5977
1251     testdir(tmpdir)
1252     trycopy("tmp.test_601", filename, tmpdir)
1253     trycopy("tmp.test_603", filename, tmpdir)
1254     download(file_url, filename, tmpdir)
1255     exe = self.bins("unzzip-mem")
1256     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1257         returncodes = [0])
1258     self.assertLess(len(run.output), 30)
1259     self.assertLess(len(run.errors), 1)
1260     self.assertIn(" 3 test", run.output)
1261   def test_603_zzipdir_mem_CVE_2017_5977(self):
1262     """ run unzzip-mem -l $(CVE_2017_5977).zip  """
1263     tmpdir = "tmp.test_603"
1264     filename = self.zip_CVE_2017_5977
1265     file_url = self.url_CVE_2017_5977
1266     testdir(tmpdir)
1267     trycopy("tmp.test_602", filename, tmpdir)
1268     trycopy("tmp.test_604", filename, tmpdir)
1269     download(file_url, filename, tmpdir)
1270     exe = self.bins("unzzip-mem")
1271     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1272         returncodes = [0])
1273     self.assertLess(len(run.output), 30)
1274     self.assertLess(len(run.errors), 1)
1275     self.assertIn(" 3 test", run.output)
1276   def test_604_zzipdir_zap_CVE_2017_5977(self):
1277     """ run unzzip-mix -l $(CVE_2017_5977).zip  """
1278     tmpdir = "tmp.test_604"
1279     filename = self.zip_CVE_2017_5977
1280     file_url = self.url_CVE_2017_5977
1281     testdir(tmpdir)
1282     trycopy("tmp.test_603", filename, tmpdir)
1283     download(file_url, filename, tmpdir)
1284     exe = self.bins("unzzip")
1285     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1286         returncodes = [0, 255])
1287     self.assertLess(len(run.output), 30)
1288     self.assertLess(len(run.errors), 1)
1289     self.assertIn(" 3 test", run.output)
1290
1291   url_CVE_2017_5978 = "https://raw.githubusercontent.com/asarubbo/poc/master/"
1292   zip_CVE_2017_5978 = "00156-zziplib-oobread-zzip_mem_entry_new"
1293   def test_610_infozipdir_CVE_2017_5978(self):
1294     """ run info-zip dir test0.zip  """
1295     tmpdir = "tmp.test_610"
1296     filename = self.zip_CVE_2017_5978
1297     file_url = self.url_CVE_2017_5978
1298     trycopy("tmp.test_611", filename, tmpdir)
1299     testdir(tmpdir)
1300     download(file_url, filename, tmpdir)
1301     exe = self.bins("unzip")
1302     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1303         returncodes = [0, 3])
1304     self.assertIn(' missing 4608 bytes in zipfile', run.errors)
1305     self.assertIn(' attempt to seek before beginning of zipfile', run.errors)
1306     self.assertLess(len(run.output), 80)
1307     self.assertLess(len(run.errors), 430)
1308   def test_611_zzipdir_big_CVE_2017_5978(self):
1309     """ run info-zip -l $(CVE_2017_5978).zip  """
1310     tmpdir = "tmp.test_611"
1311     filename = self.zip_CVE_2017_5978
1312     file_url = self.url_CVE_2017_5978
1313     testdir(tmpdir)
1314     trycopy("tmp.test_610", filename, tmpdir)
1315     trycopy("tmp.test_612", filename, tmpdir)
1316     download(file_url, filename, tmpdir)
1317     exe = self.bins("unzzip-big")
1318     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1319         returncodes = [0])
1320     self.assertLess(len(run.output), 30)
1321     self.assertLess(len(run.errors), 1)
1322     self.assertIn(" stored (null)", run.output)
1323   def test_612_zzipdir_mem_CVE_2017_5978(self):
1324     """ run unzzip-mem -l $(CVE_2017_5978).zip  """
1325     tmpdir = "tmp.test_612"
1326     filename = self.zip_CVE_2017_5978
1327     file_url = self.url_CVE_2017_5978
1328     testdir(tmpdir)
1329     trycopy("tmp.test_611", filename, tmpdir)
1330     trycopy("tmp.test_613", filename, tmpdir)
1331     download(file_url, filename, tmpdir)
1332     exe = self.bins("unzzip-mem")
1333     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1334         returncodes = [0])
1335     self.assertLess(len(run.output), 1)
1336     self.assertLess(len(run.errors), 180)
1337     self.assertIn("zzip_mem_disk_load : unable to load entry", run.errors)
1338     self.assertIn("zzip_mem_disk_open : unable to load disk", run.errors)
1339   def test_613_zzipdir_mem_CVE_2017_5978(self):
1340     """ run unzzip-mem -l $(CVE_2017_5978).zip  """
1341     tmpdir = "tmp.test_613"
1342     filename = self.zip_CVE_2017_5978
1343     file_url = self.url_CVE_2017_5978
1344     testdir(tmpdir)
1345     trycopy("tmp.test_612", filename, tmpdir)
1346     trycopy("tmp.test_614", filename, tmpdir)
1347     download(file_url, filename, tmpdir)
1348     exe = self.bins("unzzip-mem")
1349     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1350         returncodes = [0])
1351     self.assertLess(len(run.output), 1)
1352     self.assertLess(len(run.errors), 180)
1353     self.assertIn("zzip_mem_disk_load : unable to load entry", run.errors)
1354     self.assertIn("zzip_mem_disk_open : unable to load disk", run.errors)
1355   @unittest.expectedFailure
1356   def test_614_zzipdir_zap_CVE_2017_5978(self):
1357     """ run unzzip-mix -l $(CVE_2017_5978).zip  """
1358     tmpdir = "tmp.test_614"
1359     filename = self.zip_CVE_2017_5978
1360     file_url = self.url_CVE_2017_5978
1361     testdir(tmpdir)
1362     trycopy("tmp.test_613", filename, tmpdir)
1363     download(file_url, filename, tmpdir)
1364     exe = self.bins("unzzip")
1365     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1366         returncodes = [0, 255])
1367     self.assertLess(len(run.output), 1)
1368     self.assertLess(len(run.errors), 180)
1369     self.assertIn("zzip_mem_disk_load : unable to load entry", run.errors)
1370     self.assertIn("zzip_mem_disk_open : unable to load disk", run.errors)
1371
1372   url_CVE_2017_5979 = "https://raw.githubusercontent.com/asarubbo/poc/master/"
1373   zip_CVE_2017_5979 = "00157-zziplib-nullptr-prescan_entry"
1374   def test_620_infozipdir_CVE_2017_5979(self):
1375     """ run info-zip dir test0.zip  """
1376     tmpdir = "tmp.test_620"
1377     filename = self.zip_CVE_2017_5979
1378     file_url = self.url_CVE_2017_5979
1379     trycopy("tmp.test_621", filename, tmpdir)
1380     testdir(tmpdir)
1381     download(file_url, filename, tmpdir)
1382     exe = self.bins("unzip")
1383     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1384         returncodes = [0])
1385     self.assertIn(' 1 file', run.output)
1386     self.assertLess(len(run.output), 330)
1387     self.assertLess(len(run.errors), 1)
1388   def test_621_zzipdir_big_CVE_2017_5979(self):
1389     """ run info-zip -l $(CVE_2017_5979).zip  """
1390     tmpdir = "tmp.test_621"
1391     filename = self.zip_CVE_2017_5979
1392     file_url = self.url_CVE_2017_5979
1393     testdir(tmpdir)
1394     trycopy("tmp.test_620", filename, tmpdir)
1395     trycopy("tmp.test_622", filename, tmpdir)
1396     download(file_url, filename, tmpdir)
1397     exe = self.bins("unzzip-big")
1398     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1399         returncodes = [0])
1400     self.assertLess(len(run.output), 30)
1401     self.assertLess(len(run.errors), 1)
1402     self.assertIn(" stored a", run.output)
1403   def test_622_zzipdir_mem_CVE_2017_5979(self):
1404     """ run unzzip-mem -l $(CVE_2017_5979).zip  """
1405     tmpdir = "tmp.test_622"
1406     filename = self.zip_CVE_2017_5979
1407     file_url = self.url_CVE_2017_5979
1408     testdir(tmpdir)
1409     trycopy("tmp.test_621", filename, tmpdir)
1410     trycopy("tmp.test_623", filename, tmpdir)
1411     download(file_url, filename, tmpdir)
1412     exe = self.bins("unzzip-mem")
1413     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1414         returncodes = [0])
1415     self.assertLess(len(run.output), 30)
1416     self.assertLess(len(run.errors), 1)
1417     self.assertIn(" 3 a", run.output)
1418   def test_623_zzipdir_mem_CVE_2017_5979(self):
1419     """ run unzzip-mem -l $(CVE_2017_5979).zip  """
1420     tmpdir = "tmp.test_623"
1421     filename = self.zip_CVE_2017_5979
1422     file_url = self.url_CVE_2017_5979
1423     testdir(tmpdir)
1424     trycopy("tmp.test_622", filename, tmpdir)
1425     trycopy("tmp.test_624", filename, tmpdir)
1426     download(file_url, filename, tmpdir)
1427     exe = self.bins("unzzip-mem")
1428     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1429         returncodes = [0])
1430     self.assertLess(len(run.output), 30)
1431     self.assertLess(len(run.errors), 1)
1432     self.assertIn(" 3 a", run.output)
1433   def test_624_zzipdir_zap_CVE_2017_5979(self):
1434     """ run unzzip-mix -l $(CVE_2017_5979).zip  """
1435     tmpdir = "tmp.test_624"
1436     filename = self.zip_CVE_2017_5979
1437     file_url = self.url_CVE_2017_5979
1438     testdir(tmpdir)
1439     trycopy("tmp.test_623", filename, tmpdir)
1440     download(file_url, filename, tmpdir)
1441     exe = self.bins("unzzip")
1442     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1443         returncodes = [0, 255])
1444     self.assertLess(len(run.output), 30)
1445     self.assertLess(len(run.errors), 1)
1446     self.assertIn(" 3 a", run.output)
1447
1448   url_CVE_2017_5974 = "https://raw.githubusercontent.com/asarubbo/poc/master/"
1449   zip_CVE_2017_5974 = "00150-zziplib-heapoverflow-__zzip_get32"
1450   def test_630_infozipdir_CVE_2017_5974(self):
1451     """ run info-zip dir test0.zip  """
1452     tmpdir = "tmp.test_630"
1453     filename = self.zip_CVE_2017_5974
1454     file_url = self.url_CVE_2017_5974
1455     trycopy("tmp.test_631", filename, tmpdir)
1456     testdir(tmpdir)
1457     download(file_url, filename, tmpdir)
1458     exe = self.bins("unzip")
1459     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1460         returncodes = [0, 9])
1461     self.assertIn(' 1 file', run.output)
1462     self.assertLess(len(run.output), 330)
1463     self.assertLess(len(run.errors), 1)
1464   def test_631_zzipdir_big_CVE_2017_5974(self):
1465     """ run info-zip -l $(CVE_2017_5974).zip  """
1466     tmpdir = "tmp.test_631"
1467     filename = self.zip_CVE_2017_5974
1468     file_url = self.url_CVE_2017_5974
1469     testdir(tmpdir)
1470     trycopy("tmp.test_630", filename, tmpdir)
1471     trycopy("tmp.test_632", filename, tmpdir)
1472     download(file_url, filename, tmpdir)
1473     exe = self.bins("unzzip-big")
1474     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1475         returncodes = [0])
1476     self.assertLess(len(run.output), 30)
1477     self.assertLess(len(run.errors), 1)
1478     self.assertIn(" stored test", run.output)
1479   def test_632_zzipdir_mem_CVE_2017_5974(self):
1480     """ run unzzip-mem -l $(CVE_2017_5974).zip  """
1481     tmpdir = "tmp.test_632"
1482     filename = self.zip_CVE_2017_5974
1483     file_url = self.url_CVE_2017_5974
1484     testdir(tmpdir)
1485     trycopy("tmp.test_631", filename, tmpdir)
1486     trycopy("tmp.test_633", filename, tmpdir)
1487     download(file_url, filename, tmpdir)
1488     exe = self.bins("unzzip-mem")
1489     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1490         returncodes = [0])
1491     self.assertLess(len(run.output), 30)
1492     self.assertLess(len(run.errors), 1)
1493     self.assertIn(" 3 test", run.output)
1494   def test_633_zzipdir_mem_CVE_2017_5974(self):
1495     """ run unzzip-mem -l $(CVE_2017_5974).zip  """
1496     tmpdir = "tmp.test_633"
1497     filename = self.zip_CVE_2017_5974
1498     file_url = self.url_CVE_2017_5974
1499     testdir(tmpdir)
1500     trycopy("tmp.test_632", filename, tmpdir)
1501     trycopy("tmp.test_634", filename, tmpdir)
1502     download(file_url, filename, tmpdir)
1503     exe = self.bins("unzzip-mem")
1504     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1505         returncodes = [0])
1506     self.assertLess(len(run.output), 30)
1507     self.assertLess(len(run.errors), 1)
1508     self.assertIn(" 3 test", run.output)
1509   def test_634_zzipdir_zap_CVE_2017_5974(self):
1510     """ run unzzip-mix -l $(CVE_2017_5974).zip  """
1511     tmpdir = "tmp.test_634"
1512     filename = self.zip_CVE_2017_5974
1513     file_url = self.url_CVE_2017_5974
1514     testdir(tmpdir)
1515     trycopy("tmp.test_633", filename, tmpdir)
1516     download(file_url, filename, tmpdir)
1517     exe = self.bins("unzzip")
1518     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1519         returncodes = [0, 255])
1520     self.assertLess(len(run.output), 30)
1521     self.assertLess(len(run.errors), 1)
1522     self.assertIn(" 3 test", run.output)
1523
1524   url_CVE_2017_5975 = "https://raw.githubusercontent.com/asarubbo/poc/master/"
1525   zip_CVE_2017_5975 = "00151-zziplib-heapoverflow-__zzip_get64"
1526   def test_640_infozipdir_CVE_2017_5975(self):
1527     """ run info-zip dir test0.zip  """
1528     tmpdir = "tmp.test_640"
1529     filename = self.zip_CVE_2017_5975
1530     file_url = self.url_CVE_2017_5975
1531     trycopy("tmp.test_641", filename, tmpdir)
1532     testdir(tmpdir)
1533     download(file_url, filename, tmpdir)
1534     exe = self.bins("unzip")
1535     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1536         returncodes = [0, 2])
1537     self.assertIn(' missing 10 bytes in zipfile', run.errors)
1538     self.assertIn("didn't find end-of-central-dir signature at end of central dir", run.errors)
1539     self.assertIn(' 1 file', run.output)
1540     self.assertLess(len(run.output), 330)
1541     self.assertLess(len(run.errors), 430)
1542   def test_641_zzipdir_big_CVE_2017_5975(self):
1543     """ run info-zip -l $(CVE_2017_5975).zip  """
1544     tmpdir = "tmp.test_641"
1545     filename = self.zip_CVE_2017_5975
1546     file_url = self.url_CVE_2017_5975
1547     testdir(tmpdir)
1548     trycopy("tmp.test_640", filename, tmpdir)
1549     trycopy("tmp.test_642", filename, tmpdir)
1550     download(file_url, filename, tmpdir)
1551     exe = self.bins("unzzip-big")
1552     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1553         returncodes = [0])
1554     self.assertLess(len(run.output), 30)
1555     self.assertLess(len(run.errors), 1)
1556     self.assertIn(" stored test", run.output)
1557   def test_642_zzipdir_mem_CVE_2017_5975(self):
1558     """ run unzzip-mem -l $(CVE_2017_5975).zip  """
1559     tmpdir = "tmp.test_642"
1560     filename = self.zip_CVE_2017_5975
1561     file_url = self.url_CVE_2017_5975
1562     testdir(tmpdir)
1563     trycopy("tmp.test_641", filename, tmpdir)
1564     trycopy("tmp.test_643", filename, tmpdir)
1565     download(file_url, filename, tmpdir)
1566     exe = self.bins("unzzip-mem")
1567     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1568         returncodes = [0])
1569     self.assertLess(len(run.output), 1)
1570     self.assertLess(len(run.errors), 180)
1571     self.assertIn("zzip_mem_disk_load : unable to load entry", run.errors)
1572     self.assertIn("zzip_mem_disk_open : unable to load disk", run.errors)
1573   def test_643_zzipdir_mem_CVE_2017_5975(self):
1574     """ run unzzip-mem -l $(CVE_2017_5975).zip  """
1575     tmpdir = "tmp.test_643"
1576     filename = self.zip_CVE_2017_5975
1577     file_url = self.url_CVE_2017_5975
1578     testdir(tmpdir)
1579     trycopy("tmp.test_642", filename, tmpdir)
1580     trycopy("tmp.test_644", filename, tmpdir)
1581     download(file_url, filename, tmpdir)
1582     exe = self.bins("unzzip-mem")
1583     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1584         returncodes = [0])
1585     self.assertLess(len(run.output), 1)
1586     self.assertLess(len(run.errors), 180)
1587     self.assertIn("zzip_mem_disk_load : unable to load entry", run.errors)
1588     self.assertIn("zzip_mem_disk_open : unable to load disk", run.errors)
1589   def test_644_zzipdir_zap_CVE_2017_5975(self):
1590     """ run unzzip-mix -l $(CVE_2017_5975).zip  """
1591     tmpdir = "tmp.test_644"
1592     filename = self.zip_CVE_2017_5975
1593     file_url = self.url_CVE_2017_5975
1594     testdir(tmpdir)
1595     trycopy("tmp.test_643", filename, tmpdir)
1596     download(file_url, filename, tmpdir)
1597     exe = self.bins("unzzip")
1598     run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()),
1599         returncodes = [0, 255])
1600     self.assertLess(len(run.output), 1)
1601     self.assertLess(len(run.errors), 180)
1602     self.assertIn(": Success", run.errors)
1603
1604
1605   def test_800_zzshowme_check_sfx(self):
1606     """ create an *.exe that can extract its own zip content """
1607     exe=self.bins("mkzip")
1608     exefile = "tmp.zzshowme" + exeext
1609     libstub = ".libs/zzipself" + exeext
1610     txtfile_name = readme
1611     txtfile = self.src(readme)
1612     # add the extract-stub so we have reserved the size
1613     run = shell("{exe} -0 -j {exefile}.zip {libstub}".format(**locals()))
1614     self.assertFalse(run.returncode)
1615     # add the actual content which may now be compressed
1616     run = shell("{exe} -9 -j {exefile}.zip {txtfile}".format(**locals()))
1617     self.assertFalse(run.returncode)
1618     # rename .zip to .exe and put the extract-stub at the start
1619     shutil.copy(exefile+".zip", exefile)
1620     setstub="./zzipsetstub" + exeext
1621     run = shell("{setstub} {exefile} {libstub}".format(**locals()))
1622     self.assertFalse(run.returncode)
1623     os.chmod(exefile, 0755)
1624     # now ask the new .exe to show some of its own content
1625     run = shell("./{exefile} {txtfile_name}".format(**locals()))
1626     self.assertFalse(run.returncode)
1627     txt = open(txtfile).read()
1628     self.assertEqual(txt.split("\n"), run.output.split("\n"))
1629     
1630   def test_900_make_test1w_zip(self):
1631     """ create a test1w.zip using zzip/write functions. """
1632     exe=self.bins("zzip")
1633     run = shell("{exe} --version".format(**locals()))
1634     if "- NO -" in run.output:
1635         self.skipTest("- NO -D_ZZIP_ENABLE_WRITE")
1636         return
1637     zipfile="test1w.zip"
1638     tmpdir="test1w.tmp"
1639     exe=self.bins("zzip")
1640     for i in [1,2,3,4,5,6,7,8,9]:
1641        filename = os.path.join(tmpdir,"file.%i" % i)
1642        filetext = "file-%i\n" % i
1643        self.mkfile(filename, filetext)
1644     filename = os.path.join(tmpdir,"README")
1645     filetext = self.readme()
1646     self.mkfile(filename, filetext)
1647     try: os.remove(zipfile)
1648     except: pass
1649     shell("../{exe} ../{zipfile} ??*.* README".format(**locals()), cwd=tmpdir)
1650     self.assertGreater(os.path.getsize(zipfile), 10)
1651
1652
1653
1654
1655 if __name__ == "__main__":
1656   import optparse
1657   _o = optparse.OptionParser("%prog [options] test_xxx")
1658   _o.add_option("-b", "--topsrcdir", metavar="DIR", default=topsrcdir,
1659     help="path to the top srcdir / unpack directory [%default]")
1660   _o.add_option("-t", "--testdatadir", metavar="DIR", default=testdatadir,
1661     help="path where temporary testdata is created [%default]")
1662   _o.add_option("-Z", "--mkzip", metavar="EXE", default=mkzip,
1663     help="name or path to zip.exe for *.zip creation [%default]")
1664   _o.add_option("-U", "--unzip", metavar="EXE", default=unzip,
1665     help="name or path to unzip.exe to unpack *.zip [%default]")
1666   _o.add_option("-E", "--exeext", metavar="EXT", default=exeext,
1667     help="the executable extension (automake $(EXEEXT)) [%default]")
1668   _o.add_option("--xmlresults", action="store_true", default=False,
1669     help="print output in junit xml testresult format [%default]")
1670   _o.add_option("-v", "--verbose", action="count", default=0,
1671     help="increase logging output [%default]")
1672   opt, args = _o.parse_args()
1673   logging.basicConfig(level = logging.WARNING - 10 * opt.verbose)
1674   topsrcdir = opt.topsrcdir
1675   testdatdir = opt.testdatadir
1676   mkzip = opt.mkzip
1677   unzip = opt.unzip
1678   exeext = opt.exeext
1679   if not args: args += [ "test_" ]
1680   suite = unittest.TestSuite()
1681   for arg in args:
1682     for classname in sorted(list(globals())):
1683       if not classname.endswith("Test"):
1684         continue
1685       testclass = globals()[classname]
1686       for method in sorted(dir(testclass)):
1687         if "*" not in arg: arg += "*"
1688         if arg.startswith("_"): arg = arg[1:]
1689         if matches(method, arg):
1690           suite.addTest(testclass(method))
1691   # TextTestRunner(verbosity=opt.verbose).run(suite)
1692   if opt.xmlresults:
1693     import xmlrunner
1694     Runner = xmlrunner.XMLTestRunner
1695     Runner(xmlresults).run(suite)
1696   else:
1697     Runner = unittest.TextTestRunner
1698     Runner(verbosity=opt.verbose).run(suite)
1699