mirror of https://github.com/acidanthera/audk.git
BaseTools: do basic check in FvImage with header size and signature
Add some basic check in FvImage with header size and signature. Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=1181 Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
parent
55e8ff01af
commit
0e982cf03d
|
@ -195,15 +195,17 @@ class FV (FvClassObject):
|
||||||
#
|
#
|
||||||
# Write the Fv contents to Buffer
|
# Write the Fv contents to Buffer
|
||||||
#
|
#
|
||||||
if os.path.isfile(FvOutputFile):
|
if os.path.isfile(FvOutputFile) and os.path.getsize(FvOutputFile) >= 0x48:
|
||||||
FvFileObj = open(FvOutputFile, 'rb')
|
FvFileObj = open(FvOutputFile, 'rb')
|
||||||
|
# PI FvHeader is 0x48 byte
|
||||||
|
FvHeaderBuffer = FvFileObj.read(0x48)
|
||||||
|
Signature = FvHeaderBuffer[0x28:0x32]
|
||||||
|
if Signature and Signature.startswith('_FVH'):
|
||||||
GenFdsGlobalVariable.VerboseLogger("\nGenerate %s FV Successfully" % self.UiFvName)
|
GenFdsGlobalVariable.VerboseLogger("\nGenerate %s FV Successfully" % self.UiFvName)
|
||||||
GenFdsGlobalVariable.SharpCounter = 0
|
GenFdsGlobalVariable.SharpCounter = 0
|
||||||
|
|
||||||
Buffer.write(FvFileObj.read())
|
Buffer.write(FvFileObj.read())
|
||||||
FvFileObj.seek(0)
|
FvFileObj.seek(0)
|
||||||
# PI FvHeader is 0x48 byte
|
|
||||||
FvHeaderBuffer = FvFileObj.read(0x48)
|
|
||||||
# FV alignment position.
|
# FV alignment position.
|
||||||
FvAlignmentValue = 1 << (ord(FvHeaderBuffer[0x2E]) & 0x1F)
|
FvAlignmentValue = 1 << (ord(FvHeaderBuffer[0x2E]) & 0x1F)
|
||||||
if FvAlignmentValue >= 0x400:
|
if FvAlignmentValue >= 0x400:
|
||||||
|
@ -221,6 +223,8 @@ class FV (FvClassObject):
|
||||||
FvFileObj.close()
|
FvFileObj.close()
|
||||||
GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile
|
GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile
|
||||||
GenFdsGlobalVariable.LargeFileInFvFlags.pop()
|
GenFdsGlobalVariable.LargeFileInFvFlags.pop()
|
||||||
|
else:
|
||||||
|
GenFdsGlobalVariable.ErrorLogger("Invalid FV file %s." % self.UiFvName)
|
||||||
else:
|
else:
|
||||||
GenFdsGlobalVariable.ErrorLogger("Failed to generate %s FV file." %self.UiFvName)
|
GenFdsGlobalVariable.ErrorLogger("Failed to generate %s FV file." %self.UiFvName)
|
||||||
return FvOutputFile
|
return FvOutputFile
|
||||||
|
|
Loading…
Reference in New Issue