From af0b0a952d24678a758b9662e4979129dcd4a276 Mon Sep 17 00:00:00 2001 From: Luigi Scarso Date: Fri, 24 Apr 2020 18:47:01 +0000 Subject: zziplib 0.13.71 git-svn-id: svn://tug.org/texlive/trunk@54860 c570f23f-e606-0410-a88d-b1316a301751 --- .../libs/zziplib/zziplib-src/test/CMakeLists.txt | 82 +++++++ .../libs/zziplib/zziplib-src/test/Makefile.in | 5 +- .../source/libs/zziplib/zziplib-src/test/test.zip | Bin 1361 -> 1361 bytes .../libs/zziplib/zziplib-src/test/zziptests.py | 240 +++++++++++++++------ 4 files changed, 254 insertions(+), 73 deletions(-) create mode 100644 Build/source/libs/zziplib/zziplib-src/test/CMakeLists.txt (limited to 'Build/source/libs/zziplib/zziplib-src/test') diff --git a/Build/source/libs/zziplib/zziplib-src/test/CMakeLists.txt b/Build/source/libs/zziplib/zziplib-src/test/CMakeLists.txt new file mode 100644 index 00000000000..f0f7a953281 --- /dev/null +++ b/Build/source/libs/zziplib/zziplib-src/test/CMakeLists.txt @@ -0,0 +1,82 @@ +cmake_minimum_required (VERSION 3.1) +project(zziptest VERSION "0.13.71" LANGUAGES C) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif(NOT CMAKE_BUILD_TYPE) + +include ( GNUInstallDirs ) +include ( FindPkgConfig ) + +# options ######################################################## +option(BUILD_SHARED_LIBS "Build a shared library" ON) +option(BUILD_STATIC_LIBS "Build the static library" OFF) +option(BUILD_TESTS "Build test programs" OFF) +option(MSVC_STATIC_RUNTIME "Build with static runtime libs (/MT)" ON) + +# Zlib library needed +find_package ( ZLIB REQUIRED ) +# pkg_search_module ( ZZIP zzip ) +find_package ( PythonInterp 3.5 REQUIRED ) +find_package ( UnixCommands REQUIRED ) # bash cp mv rm gzip tar +find_program ( MKZIP zip) + +set(EXEEXT ${CMAKE_EXECUTABLE_SUFFIX}) +set(README ${CMAKE_SOURCE_DIR}/README) +set(PY ${PYTHON_EXECUTABLE}) +set(srcdir ${CMAKE_CURRENT_SOURCE_DIR}) +set(topdir ${CMAKE_SOURCE_DIR}) + +# targets ######################################################## +add_executable(zzipself zzipself.c) +add_executable(zzipsetstub zzipsetstub.c) + +target_link_libraries(zzipself libzzip ZLIB::ZLIB) +target_link_libraries(zzipsetstub libzzip ZLIB::ZLIB) + +target_include_directories(zzipself PRIVATE "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(zzipsetstub PRIVATE "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") + +if(CMAKE_GENERATOR MATCHES "Makefiles") +add_custom_command(OUTPUT zzipshowme${EXEEXT} + COMMAND rm -f test + COMMAND ln -s . test + COMMAND ${MKZIP} -0 -j $@ zzipself${EXEEXT} + COMMAND ${MKZIP} -9 -j $@ ${README} + COMMAND test -s $@ || cp test2.zip $@ || true + COMMAND test ! -f $@.zip || mv $@.zip $@ + COMMAND ./zzipsetstub${EXEEXT} $@ zzipself${EXEEXT} + COMMAND chmod +x $@ + DEPENDS zzipself zzipsetstub) +add_custom_target(sfx ALL DEPENDS zzipshowme${EXEEXT}) +endif() + +add_custom_target(tests + COMMAND ${PY} ${srcdir}/zziptests.py --exeext=${EXEEXT} --topsrcdir=${topdir} -v ${TESTFLAGS} + DEPENDS ../bins/zzcat ../bins/zzdir ../bins/zziptest ../bins/zzxorcat ../bins/zzxorcopy) +add_custom_command(OUTPUT ../bins/zzcat COMMMAND cd ../bins && $(MAKE) zzcat) +add_custom_command(OUTPUT ../bins/zzdir COMMMAND cd ../bins && $(MAKE) zzdir) +add_custom_command(OUTPUT ../bins/zziptest COMMMAND cd ../bins && $(MAKE) zziptest) +add_custom_command(OUTPUT ../bins/zzxorcat COMMMAND cd ../bins && $(MAKE) zzxorcat) +add_custom_command(OUTPUT ../bins/zzxorcopy COMMMAND cd ../bins && $(MAKE) zzxorcopy) + +add_custom_command(OUTPUT test0.zip + COMMAND ${BASH} -c "test -d tmp || mkdir tmp" + COMMAND ${CP} ${README} tmp/README + COMMAND ${BASH} -c "cd tmp && ${MKZIP} ../test0.zip README" + COMMAND ${CP} test0.zip test.zip + BYPRODUCTS test.zip + VERBATIM) +add_custom_target(testzips ALL DEPENDS test0.zip) + +add_custom_target(checks + COMMAND ${BASH} -c "../bins/zzcat test/README > test.out" + COMMAND ${BASH} -c "if diff test.out ${README} >/dev/null \ + ; then rm test.out ; echo check OK; true \ + ; else rm test.out ; echo check FAIL ; false; fi" + DEPENDS ../bins/zzcat test0.zip + VERBATIM) +add_custom_target(check DEPENDS checks tests) + +# install ######################################################## +# - nothing - diff --git a/Build/source/libs/zziplib/zziplib-src/test/Makefile.in b/Build/source/libs/zziplib/zziplib-src/test/Makefile.in index 4b181c2ddcf..9d7298789ee 100644 --- a/Build/source/libs/zziplib/zziplib-src/test/Makefile.in +++ b/Build/source/libs/zziplib/zziplib-src/test/Makefile.in @@ -102,9 +102,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ac_compile_check_sizeof.m4 \ $(top_srcdir)/m4/ax_cflags_warn_all.m4 \ $(top_srcdir)/m4/ax_check_aligned_access_required.m4 \ $(top_srcdir)/m4/ax_check_enable_debug.m4 \ - $(top_srcdir)/m4/ax_configure_args.m4 \ $(top_srcdir)/m4/ax_create_pkgconfig_info.m4 \ - $(top_srcdir)/m4/ax_enable_builddir.m4 \ $(top_srcdir)/m4/ax_expand_prefix.m4 \ $(top_srcdir)/m4/ax_maintainer_mode_auto_silent.m4 \ $(top_srcdir)/m4/ax_not_enable_frame_pointer.m4 \ @@ -276,6 +274,8 @@ PAX_TAR_CREATE = @PAX_TAR_CREATE@ PAX_TAR_EXTRACT = @PAX_TAR_EXTRACT@ PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PYTHON = @PYTHON@ RANLIB = @RANLIB@ RELEASE_INFO = @RELEASE_INFO@ @@ -309,7 +309,6 @@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ -ax_enable_builddir_sed = @ax_enable_builddir_sed@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ diff --git a/Build/source/libs/zziplib/zziplib-src/test/test.zip b/Build/source/libs/zziplib/zziplib-src/test/test.zip index 2c992ea7059..c0ee4a4a3a4 100644 Binary files a/Build/source/libs/zziplib/zziplib-src/test/test.zip and b/Build/source/libs/zziplib/zziplib-src/test/test.zip differ diff --git a/Build/source/libs/zziplib/zziplib-src/test/zziptests.py b/Build/source/libs/zziplib/zziplib-src/test/zziptests.py index ea113883502..03a8b6a234d 100644 --- a/Build/source/libs/zziplib/zziplib-src/test/zziptests.py +++ b/Build/source/libs/zziplib/zziplib-src/test/zziptests.py @@ -2,14 +2,28 @@ import unittest import subprocess import logging import inspect +import sys import os import collections -import urllib import shutil import random import re +import errno from fnmatch import fnmatchcase as matches -from cStringIO import StringIO + +try: + from cStringIO import StringIO +except ImportError: + from io import StringIO + +try: + from urllib import quote_plus, urlretrieve +except ImportError: + from urllib.parse import quote_plus + from urllib.request import urlretrieve + +if sys.version[0] == '3': + basestring = str logg = logging.getLogger("test") @@ -65,7 +79,9 @@ def shell(command, shell=True, calls=False, cwd=None, env=None, lang=None, retur stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=None, env=env) if run.returncode: logg.warning("EXIT %s: %s", run.returncode, command) - output, errors = run.communicate() # run.wait() + output, errors = run.communicate() + output = output.decode('utf-8') + errors = errors.decode('utf-8') except: logg.error("*E*: %s", sh_command) for line in output.split("\n"): @@ -106,7 +122,7 @@ def download(base_url, filename, into, style = ""): data = "tmp.download" if not os.path.isdir(data): os.makedirs(data) - subname = urllib.quote_plus(base_url) + subname = quote_plus(base_url) subdir = os.path.join(data, subname) if not os.path.isdir(subdir): os.makedirs(subdir) @@ -118,10 +134,13 @@ def download(base_url, filename, into, style = ""): shutil.copy(srcfile, subfile) if not os.path.exists(subfile): logg.info("need %s", subfile) - d = urllib.urlopen(base_url + "/" + filename + style) - f = open(subfile, "w") - f.write(d.read()) - f.close() + try: + urlretrieve(base_url + "/" + filename + style, subfile) + except: + # Ensure zero-length file exists in case we couldn't + # download the file so that we won't try to + # re-download it. + open(subfile, 'a').close() # if not os.path.isdir(into): os.makedirs(into) @@ -133,7 +152,7 @@ def download(base_url, filename, into, style = ""): def output(cmd, shell=True): run = subprocess.Popen(cmd, shell=shell, stdout=subprocess.PIPE) out, err = run.communicate() - return out + return out.decode('utf-8') def grep(pattern, lines): if isinstance(lines, basestring): lines = lines.split("\n") @@ -167,6 +186,8 @@ class ZZipTest(unittest.TestCase): return topsrcdir def src(self, name): return os.path.join(self.s, name) + def assertErrorMessage(self, errors, errno): + self.assertIn(': ' + os.strerror(errno), errors) def readme(self): f = open(self.src(readme)) text = f.read() @@ -196,7 +217,7 @@ class ZZipTest(unittest.TestCase): result = StringIO() old1 = '' old2 = '' - for i in xrange(size): + for i in range(size): while True: x = random.choice(" abcdefghijklmnopqrstuvwxyz\n") if x == old1 or x == old2: continue @@ -278,7 +299,7 @@ class ZZipTest(unittest.TestCase): zipfile="test2.zip" tmpdir="test2.tmp" exe=self.bins("mkzip") - for i in xrange(100): + for i in range(100): filename = os.path.join(tmpdir,"file.%02i" % i) filetext = "file-%02i\n" % i self.mkfile(filename, filetext) @@ -294,7 +315,7 @@ class ZZipTest(unittest.TestCase): zipfile="test3.zip" tmpdir="test3.tmp" exe=self.bins("mkzip") - for i in xrange(1000): + for i in range(1000): filename = os.path.join(tmpdir,"file.%03i" % i) filetext = "file-%03i\n" % i self.mkfile(filename, filetext) @@ -311,7 +332,7 @@ class ZZipTest(unittest.TestCase): zipfile="test4.zip" tmpdir="test4.tmp" exe=self.bins("mkzip") - for i in xrange(10000): + for i in range(10000): filename = os.path.join(tmpdir,"file%04i.txt" % i) filetext = "file-%04i\n" % i self.mkfile(filename, filetext) @@ -328,12 +349,12 @@ class ZZipTest(unittest.TestCase): zipfile="test5.zip" tmpdir="test5.tmp" exe=self.bins("mkzip") - for depth in xrange(20): + for depth in range(20): dirpath = "" - for i in xrange(depth): + for i in range(depth): if i: dirpath += "subdir%i/" % i - for size in xrange(18): + for size in range(18): size = 2 ** size filetext = self.gentext(size) filepart = "file%i-%i.txt" % (depth, size) @@ -1315,10 +1336,9 @@ class ZZipTest(unittest.TestCase): # run = shell("cd {tmpdir} && {exe} -o {filename}".format(**locals()), returncodes = [2]) - self.assertLess(len(run.output), 90) + self.assertLess(len(run.output), 101) self.assertLess(len(errors(run.errors)), 900) self.assertIn('test: mismatching "local" filename', run.errors) - self.assertIn('test: unknown compression method', run.errors) self.assertEqual(os.path.getsize(tmpdir+"/test"), 0) self.rm_testdir() def test_59771_zzipdir_big_CVE_2017_5977(self): @@ -1483,13 +1503,13 @@ class ZZipTest(unittest.TestCase): returncodes = [0,2]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 180) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,2]) self.assertLess(len(run.output), 30) self.assertLess(len(errors(run.errors)), 300) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) self.assertFalse(os.path.exists(tmpdir+"/test")) # self.assertEqual(os.path.getsize(tmpdir+"/test"), 0) self.rm_testdir() @@ -1817,13 +1837,13 @@ class ZZipTest(unittest.TestCase): returncodes = [0,2]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 180) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,2]) self.assertLess(len(run.output), 30) self.assertLess(len(errors(run.errors)), 200) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) self.assertFalse(os.path.exists(tmpdir+"/test")) self.rm_testdir() def test_59754_zzipdir_zap_CVE_2017_5975(self): @@ -1837,7 +1857,7 @@ class ZZipTest(unittest.TestCase): returncodes = [0,3]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 180) - self.assertIn(": Success", run.errors) + self.assertErrorMessage(run.errors, 0) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,3]) @@ -2046,7 +2066,7 @@ class ZZipTest(unittest.TestCase): returncodes = [2]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 180) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [2]) @@ -2066,7 +2086,7 @@ class ZZipTest(unittest.TestCase): returncodes = [3]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 180) - self.assertIn(": Success", run.errors) + self.assertErrorMessage(run.errors, 0) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [3]) # TODO @@ -2158,7 +2178,7 @@ class ZZipTest(unittest.TestCase): run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), returncodes = [0,2]) self.assertLess(len(run.output), 1) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,2]) @@ -2178,7 +2198,7 @@ class ZZipTest(unittest.TestCase): returncodes = [0,3]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 80) - self.assertIn(": Success", run.errors) + self.assertErrorMessage(run.errors, 0) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,3]) @@ -2268,7 +2288,7 @@ class ZZipTest(unittest.TestCase): run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), returncodes = [0,2]) self.assertLess(len(run.output), 1) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,2]) @@ -2288,7 +2308,7 @@ class ZZipTest(unittest.TestCase): returncodes = [0,3]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 80) - self.assertIn(": Success", run.errors) + self.assertErrorMessage(run.errors, 0) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,3]) @@ -2308,7 +2328,7 @@ class ZZipTest(unittest.TestCase): returncodes = [1]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 80) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) def test_63019(self): """ check $(CVE).zip """ tmpdir = self.testdir() @@ -2390,7 +2410,7 @@ class ZZipTest(unittest.TestCase): run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), returncodes = [0,2]) self.assertLess(len(run.output), 1) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,2]) @@ -2410,7 +2430,7 @@ class ZZipTest(unittest.TestCase): returncodes = [0,3]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 90) - self.assertIn(": Success", run.errors) + self.assertErrorMessage(run.errors, 0) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,3]) @@ -2524,7 +2544,7 @@ class ZZipTest(unittest.TestCase): returncodes = [0,3]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 200) - self.assertIn(": Success", run.errors) + self.assertErrorMessage(run.errors, 0) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,3]) @@ -2614,7 +2634,7 @@ class ZZipTest(unittest.TestCase): run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), returncodes = [0, 2]) self.assertLess(len(run.output), 1) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,2]) @@ -2634,7 +2654,7 @@ class ZZipTest(unittest.TestCase): returncodes = [0, 3]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 200) - self.assertIn(": Success", run.errors) + self.assertErrorMessage(run.errors, 0) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,3]) @@ -2654,7 +2674,7 @@ class ZZipTest(unittest.TestCase): returncodes = [1]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 200) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) self.rm_testdir() def test_64849(self): """ check $(CVE).zip """ @@ -2737,7 +2757,7 @@ class ZZipTest(unittest.TestCase): run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), returncodes = [0,2]) self.assertLess(len(run.output), 1) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,2]) @@ -2757,7 +2777,7 @@ class ZZipTest(unittest.TestCase): returncodes = [0, 3]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 200) - self.assertIn(": Success", run.errors) + self.assertErrorMessage(run.errors, 0) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,3]) @@ -2847,7 +2867,7 @@ class ZZipTest(unittest.TestCase): run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), returncodes = [0,2]) self.assertLess(len(run.output), 1) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,2]) @@ -2867,7 +2887,7 @@ class ZZipTest(unittest.TestCase): returncodes = [0, 3]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 200) - self.assertIn(": Success", run.errors) + self.assertErrorMessage(run.errors, 0) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,3]) @@ -2964,12 +2984,12 @@ class ZZipTest(unittest.TestCase): run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), returncodes = [0,2]) self.assertLess(len(run.output), 1) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,2]) self.assertLess(len(run.output), 30) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) # self.assertEqual(os.path.getsize(tmpdir+"/test"), 3) self.assertFalse(os.path.exists(tmpdir+"/test")) self.rm_testdir() @@ -2984,7 +3004,7 @@ class ZZipTest(unittest.TestCase): returncodes = [0, 3]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 200) - self.assertIn(": Success", run.errors) + self.assertErrorMessage(run.errors, 0) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,3]) @@ -3014,7 +3034,7 @@ class ZZipTest(unittest.TestCase): download_raw(file_url, filename, tmpdir) exe = self.bins("unzip") run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), - returncodes = [0, 80]) + returncodes = [3]) self.assertIn("missing 18 bytes in zipfile", run.errors) self.assertLess(len(run.output), 200) self.assertLess(len(errors(run.errors)), 800) @@ -3052,14 +3072,18 @@ class ZZipTest(unittest.TestCase): download_raw(file_url, filename, tmpdir) exe = self.bins("unzip") run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), - returncodes = [0, 80]) + returncodes = [3]) self.assertIn("missing 18 bytes in zipfile", run.errors) - self.assertLess(len(run.output), 200) + self.assertGreater(len(run.output), 30) + self.assertGreater(len(errors(run.errors)), 1) + self.assertLess(len(run.output), 500) self.assertLess(len(errors(run.errors)), 800) # run = shell("cd {tmpdir} && {exe} -o {filename}".format(**locals()), returncodes = [3]) - self.assertLess(len(run.output), 200) + self.assertGreater(len(run.output), 30) + self.assertGreater(len(errors(run.errors)), 1) + self.assertLess(len(run.output), 400) self.assertLess(len(errors(run.errors)), 800) self.assertIn("missing 18 bytes in zipfile", run.errors) self.assertIn('expected central file header signature not found', run.errors) @@ -3082,13 +3106,16 @@ class ZZipTest(unittest.TestCase): url_CVE_2018_27 = "https://github.com/ret2libc/---provided-by-email---" zip_CVE_2018_27 = "poc_bypass_fix2.zip" + zip_CVE_2018_27_size = 56 def test_65450(self): """ info unzip -l $(CVE).zip """ tmpdir = self.testdir() filename = self.zip_CVE_2018_27 file_url = self.url_CVE_2018_27 + filesize = self.zip_CVE_2018_27_size download_raw(file_url, filename, tmpdir) if not os.path.isfile(os.path.join(tmpdir, filename)): self.skipTest("missing " + filename) + if ((os.path.getsize(os.path.join(tmpdir, filename)) != filesize)): self.skipTest("missing " + filename) exe = self.bins("unzip") run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), returncodes = [0, 9]) @@ -3109,8 +3136,10 @@ class ZZipTest(unittest.TestCase): tmpdir = self.testdir() filename = self.zip_CVE_2018_27 file_url = self.url_CVE_2018_27 + filesize = self.zip_CVE_2018_27_size download_raw(file_url, filename, tmpdir) if not os.path.isfile(os.path.join(tmpdir, filename)): self.skipTest("missing " + filename) + if ((os.path.getsize(os.path.join(tmpdir, filename)) != filesize)): self.skipTest("missing " + filename) exe = self.bins("unzzip-big") run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), returncodes = [0]) @@ -3128,8 +3157,10 @@ class ZZipTest(unittest.TestCase): tmpdir = self.testdir() filename = self.zip_CVE_2018_27 file_url = self.url_CVE_2018_27 + filesize = self.zip_CVE_2018_27_size download_raw(file_url, filename, tmpdir) if not os.path.isfile(os.path.join(tmpdir, filename)): self.skipTest("missing " + filename) + if ((os.path.getsize(os.path.join(tmpdir, filename)) != filesize)): self.skipTest("missing " + filename) exe = self.bins("unzzip-mem") run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), returncodes = [0]) @@ -3151,18 +3182,20 @@ class ZZipTest(unittest.TestCase): tmpdir = self.testdir() filename = self.zip_CVE_2018_27 file_url = self.url_CVE_2018_27 + filesize = self.zip_CVE_2018_27_size download_raw(file_url, filename, tmpdir) if not os.path.isfile(os.path.join(tmpdir, filename)): self.skipTest("missing " + filename) + if ((os.path.getsize(os.path.join(tmpdir, filename)) != filesize)): self.skipTest("missing " + filename) exe = self.bins("unzzip-mix") run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), returncodes = [0,2]) self.assertLess(len(run.output), 1) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,2]) self.assertLess(len(run.output), 30) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) # self.assertEqual(os.path.getsize(tmpdir+"/test"), 3) self.assertFalse(os.path.exists(tmpdir+"/test")) self.rm_testdir() @@ -3171,14 +3204,16 @@ class ZZipTest(unittest.TestCase): tmpdir = self.testdir() filename = self.zip_CVE_2018_27 file_url = self.url_CVE_2018_27 + filesize = self.zip_CVE_2018_27_size download_raw(file_url, filename, tmpdir) if not os.path.isfile(os.path.join(tmpdir, filename)): self.skipTest("missing " + filename) + if ((os.path.getsize(os.path.join(tmpdir, filename)) != filesize)): self.skipTest("missing " + filename) exe = self.bins("unzzip") run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), returncodes = [0, 3]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 200) - self.assertIn(": Success", run.errors) + self.assertErrorMessage(run.errors, 0) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,3]) @@ -3192,11 +3227,13 @@ class ZZipTest(unittest.TestCase): tmpdir = self.testdir() filename = self.zip_CVE_2018_27 file_url = self.url_CVE_2018_27 + filesize = self.zip_CVE_2018_27_size download_raw(file_url, filename, tmpdir) if not os.path.isfile(os.path.join(tmpdir, filename)): self.skipTest("missing " + filename) + if ((os.path.getsize(os.path.join(tmpdir, filename)) != filesize)): self.skipTest("missing " + filename) shell("ls -l {tmpdir}/{filename}".format(**locals())) size = os.path.getsize(os.path.join(tmpdir, filename)) - self.assertEqual(size, 56) + self.assertEqual(size, filesize) # 56 url_CVE_2018_41 = "https://github.com/fantasy7082/image_test/blob/master" zip_CVE_2018_41 = "c005-bus-zzip_parse_root_directory" # CVE-2018-7726. @@ -3315,12 +3352,12 @@ class ZZipTest(unittest.TestCase): run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), returncodes = [0,2]) self.assertLess(len(run.output), 1) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,2]) self.assertLess(len(run.output), 30) - self.assertTrue(greps(run.errors, "Invalid or")) + self.assertErrorMessage(run.errors, errno.EILSEQ) # self.assertEqual(os.path.getsize(tmpdir+"/test"), 3) self.assertFalse(os.path.exists(tmpdir+"/test")) self.rm_testdir() @@ -3336,7 +3373,7 @@ class ZZipTest(unittest.TestCase): returncodes = [0, 3]) self.assertLess(len(run.output), 1) self.assertLess(len(errors(run.errors)), 200) - self.assertIn(": Success", run.errors) + self.assertErrorMessage(run.errors, 0) # run = shell("cd {tmpdir} && ../{exe} {filename} ".format(**locals()), returncodes = [0,3]) @@ -3366,14 +3403,18 @@ class ZZipTest(unittest.TestCase): download_raw(file_url, filename, tmpdir) exe = self.bins("unzip") run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), - returncodes = [0, 80]) + returncodes = [3]) self.assertIn("missing 21 bytes in zipfile", run.errors) - self.assertLess(len(run.output), 500) + self.assertGreater(len(run.output), 20) + self.assertGreater(len(errors(run.errors)), 1) + self.assertLess(len(run.output), 2500) self.assertLess(len(errors(run.errors)), 800) # run = shell("cd {tmpdir} && {exe} -o {filename}".format(**locals()), returncodes = [3]) - self.assertLess(len(run.output), 500) + self.assertGreater(len(run.output), 20) + self.assertGreater(len(errors(run.errors)), 1) + self.assertLess(len(run.output), 2500) self.assertLess(len(errors(run.errors)), 800) self.assertIn("missing 21 bytes in zipfile", run.errors) self.assertIn('expected central file header signature not found', run.errors) @@ -3404,25 +3445,76 @@ class ZZipTest(unittest.TestCase): returncodes = [0]) self.rm_testdir() + url_CVE_2018_17828 = "https://github.com/gdraheim/zziplib/files/2415382" + zip_CVE_2018_17828 = "evil.zip" + def test_65484(self): + """ extract file with "../" in the pathname [CVE-2018-17828] """ + tmpdir = self.testdir() + filename = self.zip_CVE_2018_17828 + file_url = self.url_CVE_2018_17828 + download_raw(file_url, filename, tmpdir) + if not os.path.isfile(os.path.join(tmpdir, filename)): self.skipTest("missing " + filename) + exe = self.bins("unzzip-mem") + run = shell("{exe} -l {tmpdir}/{filename} ".format(**locals()), + returncodes = [0, 80]) + self.assertLess(len(run.output), 500) + self.assertLess(len(errors(run.errors)), 1) + # + workdir = tmpdir + "/d1/d2" + os.makedirs(workdir) + run = shell("cd {workdir} && ../../../{exe} ../../{filename} ".format(**locals()), + returncodes = [0]) + self.assertLess(len(run.output), 500) + self.assertEqual(len(errors(run.errors)), 1) + self.assertFalse(os.path.exists(tmpdir+"/test/evil.conf")) + self.assertTrue(os.path.exists(workdir+"/test/evil.conf")) + self.rm_testdir() + + def test_65485_list_verbose_compressed_with_directory(self): + """ verbously list a zipfile containing directories """ + chdir = "chdir" + if not exeext: chdir = "cd" + tmpdir = self.testdir() + workdir = tmpdir + "/d" + zipname = "ZIPfile" + os.makedirs(workdir) + f= open(tmpdir + "/d/file","w+") + for i in range(10): + f.write("This is line %d\r\n" % (i+1)) + f.close() + # create the ZIPfile + mkzip=self.bins("mkzip") + run = shell("{chdir} {tmpdir} && {mkzip} -9 {zipname}.zip d".format(**locals())) + self.assertFalse(run.returncode) + # list the ZIPfile + exe=self.bins("unzip-mem"); + run = shell("{chdir} {tmpdir} && ../{exe} -v {zipname}.zip".format(**locals()), returncodes = [0,-8]) + logg.error("FIXME: unzip-mem test_65485 is not solved") + self.skipTest("FIXME: not solved") + self.assertFalse(run.returncode) + self.rm_testdir() + def test_91000_zzshowme_check_sfx(self): """ create an *.exe that can extract its own zip content """ - exe=self.bins("mkzip") + mkzip=self.bins("mkzip") exefile = "tmp.zzshowme" + exeext - libstub = ".libs/zzipself" + exeext + libstub1 = ".libs/zzipself" + exeext + libstub2 = "zzipself" + exeext + libstub = os.path.exists(libstub1) and libstub1 or libstub2 txtfile_name = readme txtfile = self.src(readme) # add the extract-stub so we have reserved the size - run = shell("{exe} -0 -j {exefile}.zip {libstub}".format(**locals())) + run = shell("{mkzip} -0 -j {exefile}.zip {libstub}".format(**locals())) self.assertFalse(run.returncode) # add the actual content which may now be compressed - run = shell("{exe} -9 -j {exefile}.zip {txtfile}".format(**locals())) + run = shell("{mkzip} -9 -j {exefile}.zip {txtfile}".format(**locals())) self.assertFalse(run.returncode) # rename .zip to .exe and put the extract-stub at the start shutil.copy(exefile+".zip", exefile) setstub="./zzipsetstub" + exeext run = shell("{setstub} {exefile} {libstub}".format(**locals())) self.assertFalse(run.returncode) - os.chmod(exefile, 0755) + os.chmod(exefile, 0o755) # now ask the new .exe to show some of its own content run = shell("./{exefile} {txtfile_name}".format(**locals())) self.assertFalse(run.returncode) @@ -3468,13 +3560,14 @@ if __name__ == "__main__": help="name or path to unzip.exe to unpack *.zip [%default]") _o.add_option("-E", "--exeext", metavar="EXT", default=exeext, help="the executable extension (automake $(EXEEXT)) [%default]") - _o.add_option("--xmlresults", action="store_true", default=False, - help="print output in junit xml testresult format [%default]") + _o.add_option("--xmlresults", metavar="FILE", default=None, + help="capture results as a junit xml file [%default]") _o.add_option("-v", "--verbose", action="count", default=0, help="increase logging output [%default]") opt, args = _o.parse_args() logging.basicConfig(level = logging.WARNING - 10 * opt.verbose) topsrcdir = opt.topsrcdir + bindir = opt.bindir testdatdir = opt.testdatadir mkzip = opt.mkzip unzip = opt.unzip @@ -3491,12 +3584,19 @@ if __name__ == "__main__": if arg.startswith("_"): arg = arg[1:] if matches(method, arg): suite.addTest(testclass(method)) - # TextTestRunner(verbosity=opt.verbose).run(suite) - if opt.xmlresults: - import xmlrunner + + xmlresults = opt.xmlresults + if xmlresults: + try: import xmlrunner + except: xmlresults=None + if xmlresults: + if os.path.exists(opt.xmlresults): + os.remove(opt.xmlresults) + logg.info("xml results into %s", opt.xmlresults) Runner = xmlrunner.XMLTestRunner - Runner(xmlresults).run(suite) + result = Runner(output=opt.xmlresults).run(suite) else: Runner = unittest.TextTestRunner - Runner(verbosity=opt.verbose).run(suite) - + result = Runner(verbosity=opt.verbose).run(suite) + if not result.wasSuccessful(): + sys.exit(1) -- cgit v1.2.3