diff --git a/MdeModulePkg/Core/Dxe/Gcd/gcd.c b/MdeModulePkg/Core/Dxe/Gcd/gcd.c index 1d023548d3..3cadab29dc 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/gcd.c @@ -2473,6 +2473,9 @@ Returns: if (MemorySpaceMap[Index].ImageHandle == NULL) { BaseAddress = PageAlignAddress (MemorySpaceMap[Index].BaseAddress); Length = PageAlignLength (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - BaseAddress); + if (Length == 0 || MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length < BaseAddress) { + continue; + } CoreAddMemoryDescriptor ( EfiConventionalMemory, BaseAddress, diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index 0ac2aa5c91..97179dec85 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -1432,7 +1432,7 @@ Returns: // // Build the map // - ZeroMem (MemoryMap, Size); + ZeroMem (MemoryMap, BufferSize); for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) { Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE); ASSERT (Entry->VirtualStart == 0);