Skip to content

Commit f3d0961

Browse files
Ashwin Rameshdzier
authored andcommitted
Added YAML security fixes
1 parent 47d1448 commit f3d0961

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

model_analyzer/config/input/config_command.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class ConfigCommand:
2121
"""
2222
Model Analyzer config object.
2323
"""
24-
2524
def __init__(self):
2625
"""
2726
Create a new config.
@@ -69,7 +68,7 @@ def _load_config_file(self, file_path):
6968
"""
7069

7170
with open(file_path, 'r') as config_file:
72-
config = yaml.load(config_file, Loader=yaml.FullLoader)
71+
config = yaml.safe_load(config_file, Loader=yaml.FullLoader)
7372
return config
7473

7574
def set_config_values(self, args):

qa/L0_config_range/config_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def get_all_configurations():
115115
with open(f'./config-{i}.yml', 'w') as file:
116116
yaml.dump(configuration, file)
117117
with open(f'./config-{i}.yml', 'r') as file:
118-
config = yaml.load(file, Loader=yaml.FullLoader)
118+
config = yaml.safe_load(file, Loader=yaml.FullLoader)
119119
with open(f'./config-{i}.txt', 'w') as file:
120120
file.write(str(total_param))
121121

qa/L0_custom_flags/check_results.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def check_perf_global(self):
5252
True if test passes else False
5353
"""
5454

55-
if 'perf_analyzer_flags' in self._config and 'percentile' in self._config['perf_analyzer_flags']:
55+
if 'perf_analyzer_flags' in self._config and 'percentile' in self._config[
56+
'perf_analyzer_flags']:
5657
with open(self._analyzer_log, 'r') as f:
5758
contents = f.read()
5859

@@ -80,13 +81,15 @@ def check_perf_mode_time_window(self):
8081
True if test passes else False
8182
"""
8283

83-
if 'perf_analyzer_flags' in self._config and 'measurement-mode' in self._config['perf_analyzer_flags']:
84+
if 'perf_analyzer_flags' in self._config and 'measurement-mode' in self._config[
85+
'perf_analyzer_flags']:
8486
with open(self._analyzer_log, 'r') as f:
8587
contents = f.read()
8688

8789
# In contents, search for "stabilizing with px latency"
88-
measurement_mode = self._config['perf_analyzer_flags']['measurement-mode']
89-
assert(measurement_mode == 'time_windows')
90+
measurement_mode = self._config['perf_analyzer_flags'][
91+
'measurement-mode']
92+
assert (measurement_mode == 'time_windows')
9093
token = "time_windows"
9194

9295
# Ensure the token appears in the text
@@ -229,7 +232,7 @@ def check_triton_per_model(self):
229232
args = parser.parse_args()
230233

231234
with open(args.config_file, 'r') as f:
232-
config = yaml.load(f, Loader=yaml.FullLoader)
235+
config = yaml.safe_load(f, Loader=yaml.FullLoader)
233236

234237
TestOutputValidator(config, args.profile_models, args.analyzer_log_file,
235238
args.triton_log_file)

qa/L0_perf_analyzer/check_results.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class TestOutputValidator:
2222
Functions that validate the output
2323
of the test
2424
"""
25-
2625
def __init__(self, config, config_file, analyzer_log, test_name):
2726
self._config = config
2827
self._config_file = config_file
@@ -72,7 +71,7 @@ def check_time_window_50(self):
7271
args = parser.parse_args()
7372

7473
with open(args.config_file, 'r') as f:
75-
config = yaml.load(f, Loader=yaml.FullLoader)
74+
config = yaml.safe_load(f, Loader=yaml.FullLoader)
7675

7776
TestOutputValidator(config, args.config_file, args.analyzer_log,
7877
args.test_name)

qa/L0_profile/check_results.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class TestOutputValidator:
2424
Functions that validate the output
2525
of the test
2626
"""
27-
2827
def __init__(self, config, test_name, analyzer_log):
2928
self._config = config
3029
self._models = config['profile_models']
@@ -87,6 +86,6 @@ def check_profile_logs(self):
8786
args = parser.parse_args()
8887

8988
with open(args.config_file, 'r') as f:
90-
config = yaml.load(f, Loader=yaml.FullLoader)
89+
config = yaml.safe_load(f, Loader=yaml.FullLoader)
9190

9291
TestOutputValidator(config, args.test_name, args.analyzer_log_file)

qa/L0_results/check_results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,6 @@ def check_detailed_reports(self):
106106
args = parser.parse_args()
107107

108108
with open(args.config_file, 'r') as f:
109-
config = yaml.load(f, Loader=yaml.FullLoader)
109+
config = yaml.safe_load(f, Loader=yaml.FullLoader)
110110

111111
TestOutputValidator(config, args.test_name, args.export_path)

qa/L0_state_management/check_results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def check_measurements_consistent_with_config(self):
180180
args = parser.parse_args()
181181

182182
with open(args.config_file, 'r') as f:
183-
config = yaml.load(f, Loader=yaml.FullLoader)
183+
config = yaml.safe_load(f, Loader=yaml.FullLoader)
184184

185185
TestOutputValidator(config, args.test_name, args.checkpoint_dir,
186186
args.analyzer_log_file)

0 commit comments

Comments
 (0)