diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c index 1e8f573009..6d36b6dff0 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -488,6 +488,15 @@ PeCoffLoaderImageAddress ( IN UINTN Address ) { + // + // @bug Check to make sure ImageSize is correct for the relocated image. + // it may only work for the file we start with and not the relocated image + // + if (Address >= ImageContext->ImageSize) { + ImageContext->ImageError = IMAGE_ERROR_INVALID_IMAGE_ADDRESS; + return NULL; + } + return (CHAR8 *)((UINTN) ImageContext->ImageAddress + Address); }