From 30399d94f6dff50a21236baba16e011ddff94fab Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 27 Jun 2016 13:18:12 -0700 Subject: [PATCH] A few more sanity checks for detecting unzip output that's not a file entry (#3982) * A few more sanity checks for detecting unzip output that's not a file entry Also note that there's a rounding error somewhere in the mtime comparison code. * Fix reference to sub-array --- lib/ansible/modules/files/unarchive.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/files/unarchive.py b/lib/ansible/modules/files/unarchive.py index f79e8904ec2..2d07b8caf41 100644 --- a/lib/ansible/modules/files/unarchive.py +++ b/lib/ansible/modules/files/unarchive.py @@ -314,13 +314,19 @@ class ZipArchive(object): change = False pcs = line.split(None, 7) + if len(pcs) != 8: + # Too few fields... probably a piece of the header or footer + continue # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue if len(pcs[6]) != 15: continue + if pcs[0][0] not in 'dl-?' or not frozenset(pcs[0][1:]).issubset('rwxst-'): + continue + ztype = pcs[0][0] - permstr = pcs[0][1:10] + permstr = pcs[0][1:] version = pcs[1] ostype = pcs[2] size = int(pcs[3]) @@ -394,6 +400,9 @@ class ZipArchive(object): itemized = list('.%s.......??' % ftype) + # Note: this timestamp calculation has a rounding error + # somewhere... unzip and this timestamp can be one second off + # When that happens, we report a change and re-unzip the file dt_object = datetime.datetime(*(time.strptime(pcs[6], '%Y%m%d.%H%M%S')[0:6])) timestamp = time.mktime(dt_object.timetuple())