Skip to content

Commit

Permalink
[202405] ImageValidation.py: Don't parse entire image (#1127)
Browse files Browse the repository at this point in the history
## Description

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
(erocarrera/pefile#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.

See: microsoft/mu_tiano_platforms#1025 and
erocarrera/pefile#421

- [ ] Impacts functionality?
- [ ] Impacts security?
- [ ] Breaking change?
- [ ] Includes tests?
- [ ] Includes documentation?

## How This Was Tested

Validated pipelines build on mu_tiano_platforms

## Integration Instructions

N/A
  • Loading branch information
Javagedes authored Aug 29, 2024
1 parent 0a17aa9 commit f2a5ec9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions .pytool/Plugin/ImageValidation/ImageValidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f2a5ec9

Please sign in to comment.