diff options
Diffstat (limited to 'MdePkg/Library/BasePeCoffLib/BasePeCoff.c')
-rw-r--r-- | MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c index 5be6e90379..eeabbb24bc 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -926,6 +926,14 @@ PeCoffLoaderLoadImage ( Section = FirstSection;
for (Index = 0, MaxEnd = NULL; Index < NumberOfSections; Index++) {
//
+ // Read the section
+ //
+ Size = (UINTN) Section->Misc.VirtualSize;
+ if ((Size == 0) || (Size > Section->SizeOfRawData)) {
+ Size = (UINTN) Section->SizeOfRawData;
+ }
+
+ //
// Compute sections address
//
Base = PeCoffLoaderImageAddress (ImageContext, Section->VirtualAddress);
@@ -935,9 +943,9 @@ PeCoffLoaderLoadImage ( );
//
- // If the base start or end address resolved to 0, then fail.
+ // If the size of the section is non-zero and the base address or end address resolved to 0, then fail.
//
- if ((Base == NULL) || (End == NULL)) {
+ if ((Size > 0) && ((Base == NULL) || (End == NULL))) {
ImageContext->ImageError = IMAGE_ERROR_SECTION_NOT_LOADED;
return RETURN_LOAD_ERROR;
}
@@ -951,14 +959,6 @@ PeCoffLoaderLoadImage ( MaxEnd = End;
}
- //
- // Read the section
- //
- Size = (UINTN) Section->Misc.VirtualSize;
- if ((Size == 0) || (Size > Section->SizeOfRawData)) {
- Size = (UINTN) Section->SizeOfRawData;
- }
-
if (Section->SizeOfRawData > 0) {
if (!(ImageContext->IsTeImage)) {
Status = ImageContext->ImageRead (
|