Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit 73e21e9

Browse files
authored
Update repro get_files to handle regression reports (#3340)
* Add support for regression reports to 'repro get_files' * Make get_files logic more clear * Format api.py with black * Change crash_info default values for mypy * Set crash_info['input_blob_container'] as a Container instead of string * Add logic for handling a missing 'original_crash_test_result' or missing 'crash_report's * Adjust code format in get_files * Update logic to comply with mypy * Fix missing dict index operation
1 parent 62c3f07 commit 73e21e9

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

src/cli/onefuzz/api.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -557,23 +557,60 @@ def get_files(
557557
report_bytes = self.onefuzz.containers.files.get(report_container, report_name)
558558
report = json.loads(report_bytes)
559559

560+
crash_info = {
561+
"input_blob_container": primitives.Container(""),
562+
"input_blob_name": "",
563+
"job_id": "",
564+
}
565+
if "input_blob" in report:
566+
crash_info["input_blob_container"] = report["input_blob"]["container"]
567+
crash_info["input_blob_name"] = report["input_blob"]["name"]
568+
crash_info["job_id"] = report["job_id"]
569+
elif "crash_test_result" in report and "original_crash_test_result" in report:
570+
if report["original_crash_test_result"]["crash_report"] is None:
571+
self.logger.error(
572+
"No crash report found in the original crash test result, repro files cannot be retrieved"
573+
)
574+
return
575+
elif report["crash_test_result"]["crash_report"] is None:
576+
self.logger.info(
577+
"No crash report found in the new crash test result, falling back on the original crash test result for job_id"
578+
"Note: if using --include_setup, the downloaded fuzzer binaries may be out-of-date"
579+
)
580+
581+
original_report = report["original_crash_test_result"]["crash_report"]
582+
new_report = (
583+
report["crash_test_result"]["crash_report"] or original_report
584+
) # fallback on original_report
585+
586+
crash_info["input_blob_container"] = original_report["input_blob"][
587+
"container"
588+
]
589+
crash_info["input_blob_name"] = original_report["input_blob"]["name"]
590+
crash_info["job_id"] = new_report["job_id"]
591+
else:
592+
self.logger.error(
593+
"Encountered an unhandled report format, repro files cannot be retrieved"
594+
)
595+
return
596+
560597
self.logger.info(
561598
"downloading files necessary to locally repro crash %s",
562-
report["input_blob"]["name"],
599+
crash_info["input_blob_name"],
563600
)
564-
565601
self.onefuzz.containers.files.download(
566-
report["input_blob"]["container"],
567-
report["input_blob"]["name"],
568-
os.path.join(output_dir, report["input_blob"]["name"]),
602+
primitives.Container(crash_info["input_blob_container"]),
603+
crash_info["input_blob_name"],
604+
os.path.join(output_dir, crash_info["input_blob_name"]),
569605
)
570606

571607
if include_setup:
572608
setup_container = list(
573609
self.onefuzz.jobs.containers.list(
574-
report["job_id"], enums.ContainerType.setup
610+
crash_info["job_id"], enums.ContainerType.setup
575611
)
576612
)[0]
613+
577614
self.onefuzz.containers.files.download_dir(
578615
primitives.Container(setup_container), output_dir
579616
)

0 commit comments

Comments
 (0)