From 2e8f844aa2ff53f5081789d5ff5dab9ee8d2f13f Mon Sep 17 00:00:00 2001 From: Joey Vagedes Date: Thu, 29 Aug 2024 12:27:11 -0700 Subject: [PATCH] ImageValidation.py: Don't parse entire image This commit modifies the PE parsing functionality to only parse the headers of the image, rather than the entire image. This change is made to improve performance and also the probability of failing to parse the entire image. This comes after this commit (https://github.com/erocarrera/pefile/pull/365) in pefile resulted in efi image parsing failures, breaking the build. This commit also wraps the parsing of the image in a try-except block to catch any exceptions that may be raised during parsing, to cleanly exit. --- .pytool/Plugin/ImageValidation/ImageValidation.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.pytool/Plugin/ImageValidation/ImageValidation.py b/.pytool/Plugin/ImageValidation/ImageValidation.py index 2a215b2f78..0a3de51048 100644 --- a/.pytool/Plugin/ImageValidation/ImageValidation.py +++ b/.pytool/Plugin/ImageValidation/ImageValidation.py @@ -93,7 +93,6 @@ def do_post_build(self, thebuilder): # Load Configuration Data config_path = thebuilder.env.GetValue("PE_VALIDATION_PATH", None) - tool_chain_tag = thebuilder.env.GetValue("TOOL_CHAIN_TAG") if config_path is None: logging.info("PE_VALIDATION_PATH not set, Using default configuration") logging.info("Review ImageValidation/Readme.md for configuration options.") @@ -232,7 +231,11 @@ def do_post_build(self, thebuilder): # Executes run_tests() on the efi def _validate_image(self, efi_path, profile="DEFAULT"): - pe = PE(efi_path) + try: + pe = PE(efi_path, fast_load=True) + except Exception: + logging.error(f'Failed to parse {os.path.basename(efi_path)}') + return Result.FAIL target_config = self.config_data[MACHINE_TYPE[pe.FILE_HEADER.Machine]].get( profile)