Skip to content

Commit e2e1ccf

Browse files
author
Shamal Faily
committed
Fix uncontrolled data used in path expression
1 parent 6661bd0 commit e2e1ccf

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

cairis/bin/cimport.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ def safe_extract(zf, member, target_dir):
6161
target_dir_abs = os.path.abspath(target_dir)
6262
if (os.path.commonpath([target_dir_abs, target_path]) != target_dir_abs):
6363
raise ARMException('Invalid path in package: ' + member)
64-
zf.extract(member, target_dir_abs)
64+
65+
with open(target_path, 'wb') as out_f:
66+
out_f.write(zf.read(member))
6567
return target_path
6668

6769
def package_import(pkgStr,session_id = None):
@@ -80,7 +82,8 @@ def package_import(pkgStr,session_id = None):
8082
extracted_path = safe_extract(zf, fileName, b.tmpDir)
8183
modelType = ''
8284
try:
83-
modelType = ET.fromstring(open(extracted_path).read()).tag
85+
xml_bytes = zf.read(fileName)
86+
modelType = ET.fromstring(xml_bytes).tag
8487
except ET.ParseError as e:
8588
raise ARMException('Error parsing ' + fileName + ': ' + str(e))
8689
os.remove(extracted_path)

0 commit comments

Comments
 (0)