From 068e7c5652947c4a6a367cdc107f1f1042013cd7 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 18 Jan 2014 21:30:01 +0000 Subject: Fix https://labs.riseup.net/code/issues/6604 --- MAT/archive.py | 6 +++++- test/libtest.py | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/MAT/archive.py b/MAT/archive.py index ed55319..ee5c936 100644 --- a/MAT/archive.py +++ b/MAT/archive.py @@ -5,6 +5,7 @@ import datetime import logging import os import shutil +import stat import tarfile import tempfile import zipfile @@ -160,7 +161,10 @@ class ZipStripper(GenericArchiveStripper): if os.path.isfile(name) and not beginning and not ending: cfile = mat.create_class_file(name, False, add2archive=self.add2archive) if cfile is not None: + old_stat = os.stat(name).st_mode + os.chmod(name, old_stat|stat.S_IWUSR) cfile.remove_all() + os.chmod(name, old_stat) logging.debug('Processing %s from %s' % (item.filename, self.filename)) elif item.filename not in whitelist: logging.info('%s\'s format is not supported or harmless' % item.filename) @@ -244,10 +248,10 @@ class TarStripper(GenericArchiveStripper): class_file = mat.create_class_file(complete_name, False, add2archive=self.add2archive) if class_file: - # Nested archives are treated like unsupported ones if not class_file.is_clean(): if not list_unsupported: return False + # Nested archives are treated like unsupported files elif isinstance(class_file, GenericArchiveStripper): ret_list.append(item.name) else: diff --git a/test/libtest.py b/test/libtest.py index f052b6e..cbc807f 100644 --- a/test/libtest.py +++ b/test/libtest.py @@ -7,6 +7,7 @@ import os import sys +import shutil import tarfile import tempfile import test @@ -157,6 +158,13 @@ class TestArchiveProcessing(test.MATTest): unsupported_files = set(current_file.is_clean(list_unsupported=True)) self.assertEqual(unsupported_files, set(('mat.desktop', 'README.security', 'setup.py'))) + def test_archive_unwritable_content(self): + path = os.path.join(self.tmpdir, './unwritable_content.zip') + shutil.copy2('./unwritable_content.zip', self.tmpdir) + current_file = MAT.mat.create_class_file(path, False, add2archive=False) + current_file.remove_all() + current_file = MAT.mat.create_class_file(path, False, add2archive=False) + self.assertTrue(current_file.is_clean()) def get_tests(): ''' Returns every libtests''' -- cgit v1.3