diff options
| -rw-r--r-- | MAT/archive.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/MAT/archive.py b/MAT/archive.py index dd8dc63..4e24316 100644 --- a/MAT/archive.py +++ b/MAT/archive.py | |||
| @@ -40,6 +40,8 @@ class GenericArchiveStripper(parser.GenericParser): | |||
| 40 | shutil.rmtree(self.tempdir) | 40 | shutil.rmtree(self.tempdir) |
| 41 | 41 | ||
| 42 | def is_clean(self, list_unsupported): | 42 | def is_clean(self, list_unsupported): |
| 43 | ''' Virtual method to check for harmul metadata | ||
| 44 | ''' | ||
| 43 | raise NotImplementedError | 45 | raise NotImplementedError |
| 44 | 46 | ||
| 45 | def list_unsupported(self): | 47 | def list_unsupported(self): |
| @@ -57,8 +59,8 @@ class ZipStripper(GenericArchiveStripper): | |||
| 57 | ''' Represent a zip file | 59 | ''' Represent a zip file |
| 58 | ''' | 60 | ''' |
| 59 | def __is_zipfile_clean(self, fileinfo): | 61 | def __is_zipfile_clean(self, fileinfo): |
| 60 | ''' Check if a ZipInfo object is clean of metadatas added | 62 | ''' Check if a ZipInfo object is clean of metadata added |
| 61 | by zip itself, independently of the corresponding file metadatas | 63 | by zip itself, independently of the corresponding file metadata |
| 62 | ''' | 64 | ''' |
| 63 | if fileinfo.comment != '': | 65 | if fileinfo.comment != '': |
| 64 | return False | 66 | return False |
| @@ -70,6 +72,9 @@ class ZipStripper(GenericArchiveStripper): | |||
| 70 | 72 | ||
| 71 | def is_clean(self, list_unsupported=False): | 73 | def is_clean(self, list_unsupported=False): |
| 72 | ''' Check if the given file is clean from harmful metadata | 74 | ''' Check if the given file is clean from harmful metadata |
| 75 | When list_unsupported is True, the method returns a list | ||
| 76 | of all non-supported/archives files contained in the | ||
| 77 | archive. | ||
| 73 | ''' | 78 | ''' |
| 74 | if list_unsupported: | 79 | if list_unsupported: |
| 75 | ret_list = [] | 80 | ret_list = [] |
| @@ -186,7 +191,7 @@ class TarStripper(GenericArchiveStripper): | |||
| 186 | ''' Represent a tarfile archive | 191 | ''' Represent a tarfile archive |
| 187 | ''' | 192 | ''' |
| 188 | def _remove(self, current_file): | 193 | def _remove(self, current_file): |
| 189 | ''' Remove the meta added by tar itself to the file | 194 | ''' Remove the meta added by tarfile itself to the file |
| 190 | ''' | 195 | ''' |
| 191 | current_file.mtime = 0 | 196 | current_file.mtime = 0 |
| 192 | current_file.uid = 0 | 197 | current_file.uid = 0 |
| @@ -196,6 +201,10 @@ class TarStripper(GenericArchiveStripper): | |||
| 196 | return current_file | 201 | return current_file |
| 197 | 202 | ||
| 198 | def remove_all(self, whitelist=[]): | 203 | def remove_all(self, whitelist=[]): |
| 204 | ''' Remove all harmful metadata from the tarfile. | ||
| 205 | The method will also add every files matching | ||
| 206 | whitelist in the produced archive. | ||
| 207 | ''' | ||
| 199 | tarin = tarfile.open(self.filename, 'r' + self.compression, encoding='utf-8') | 208 | tarin = tarfile.open(self.filename, 'r' + self.compression, encoding='utf-8') |
| 200 | tarout = tarfile.open(self.output, 'w' + self.compression, encoding='utf-8') | 209 | tarout = tarfile.open(self.output, 'w' + self.compression, encoding='utf-8') |
| 201 | for item in tarin.getmembers(): | 210 | for item in tarin.getmembers(): |
| @@ -224,7 +233,7 @@ class TarStripper(GenericArchiveStripper): | |||
| 224 | return True | 233 | return True |
| 225 | 234 | ||
| 226 | def is_file_clean(self, current_file): | 235 | def is_file_clean(self, current_file): |
| 227 | ''' Check metadatas added by tar | 236 | ''' Check metadatas added by tarfile |
| 228 | ''' | 237 | ''' |
| 229 | if current_file.mtime != 0: | 238 | if current_file.mtime != 0: |
| 230 | return False | 239 | return False |
| @@ -240,6 +249,9 @@ class TarStripper(GenericArchiveStripper): | |||
| 240 | 249 | ||
| 241 | def is_clean(self, list_unsupported=False): | 250 | def is_clean(self, list_unsupported=False): |
| 242 | ''' Check if the file is clean from harmful metadatas | 251 | ''' Check if the file is clean from harmful metadatas |
| 252 | When list_unsupported is True, the method returns a list | ||
| 253 | of all non-supported/archives files contained in the | ||
| 254 | archive. | ||
| 243 | ''' | 255 | ''' |
| 244 | if list_unsupported: | 256 | if list_unsupported: |
| 245 | ret_list = [] | 257 | ret_list = [] |
| @@ -274,7 +286,7 @@ class TarStripper(GenericArchiveStripper): | |||
| 274 | return True | 286 | return True |
| 275 | 287 | ||
| 276 | def get_meta(self): | 288 | def get_meta(self): |
| 277 | ''' Return a dict with all the meta of the file | 289 | ''' Return a dict with all the meta of the tarfile |
| 278 | ''' | 290 | ''' |
| 279 | tarin = tarfile.open(self.filename, 'r' + self.compression) | 291 | tarin = tarfile.open(self.filename, 'r' + self.compression) |
| 280 | metadata = {} | 292 | metadata = {} |
