summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/GenFds/Fv.py
diff options
context:
space:
mode:
authorzhijufan <zhijux.fan@intel.com>2018-09-25 10:55:46 +0800
committerYonghong Zhu <yonghong.zhu@intel.com>2018-10-15 10:16:07 +0800
commit0e982cf03dd5023b90def60c3656e5e18135ebac (patch)
tree41415b46c927448c8816fb133fd000c8e3f6784a /BaseTools/Source/Python/GenFds/Fv.py
parent55e8ff01af77117dc276b3481ae364141012c52b (diff)
downloadedk2-0e982cf03dd5023b90def60c3656e5e18135ebac.tar.gz
edk2-0e982cf03dd5023b90def60c3656e5e18135ebac.tar.bz2
edk2-0e982cf03dd5023b90def60c3656e5e18135ebac.zip
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>
Diffstat (limited to 'BaseTools/Source/Python/GenFds/Fv.py')
-rw-r--r--BaseTools/Source/Python/GenFds/Fv.py44
1 files changed, 24 insertions, 20 deletions
diff --git a/BaseTools/Source/Python/GenFds/Fv.py b/BaseTools/Source/Python/GenFds/Fv.py
index 0d005ebf5b..510f2834a8 100644
--- a/BaseTools/Source/Python/GenFds/Fv.py
+++ b/BaseTools/Source/Python/GenFds/Fv.py
@@ -195,32 +195,36 @@ class FV (FvClassObject):
#
# 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')
- GenFdsGlobalVariable.VerboseLogger("\nGenerate %s FV Successfully" % self.UiFvName)
- GenFdsGlobalVariable.SharpCounter = 0
-
- Buffer.write(FvFileObj.read())
- FvFileObj.seek(0)
# PI FvHeader is 0x48 byte
FvHeaderBuffer = FvFileObj.read(0x48)
- # FV alignment position.
- FvAlignmentValue = 1 << (ord(FvHeaderBuffer[0x2E]) & 0x1F)
- if FvAlignmentValue >= 0x400:
- if FvAlignmentValue >= 0x100000:
- if FvAlignmentValue >= 0x1000000:
- #The max alignment supported by FFS is 16M.
- self.FvAlignment = "16M"
+ Signature = FvHeaderBuffer[0x28:0x32]
+ if Signature and Signature.startswith('_FVH'):
+ GenFdsGlobalVariable.VerboseLogger("\nGenerate %s FV Successfully" % self.UiFvName)
+ GenFdsGlobalVariable.SharpCounter = 0
+
+ Buffer.write(FvFileObj.read())
+ FvFileObj.seek(0)
+ # FV alignment position.
+ FvAlignmentValue = 1 << (ord(FvHeaderBuffer[0x2E]) & 0x1F)
+ if FvAlignmentValue >= 0x400:
+ if FvAlignmentValue >= 0x100000:
+ if FvAlignmentValue >= 0x1000000:
+ #The max alignment supported by FFS is 16M.
+ self.FvAlignment = "16M"
+ else:
+ self.FvAlignment = str(FvAlignmentValue / 0x100000) + "M"
else:
- self.FvAlignment = str(FvAlignmentValue / 0x100000) + "M"
+ self.FvAlignment = str(FvAlignmentValue / 0x400) + "K"
else:
- self.FvAlignment = str(FvAlignmentValue / 0x400) + "K"
+ # FvAlignmentValue is less than 1K
+ self.FvAlignment = str (FvAlignmentValue)
+ FvFileObj.close()
+ GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile
+ GenFdsGlobalVariable.LargeFileInFvFlags.pop()
else:
- # FvAlignmentValue is less than 1K
- self.FvAlignment = str (FvAlignmentValue)
- FvFileObj.close()
- GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile
- GenFdsGlobalVariable.LargeFileInFvFlags.pop()
+ GenFdsGlobalVariable.ErrorLogger("Invalid FV file %s." % self.UiFvName)
else:
GenFdsGlobalVariable.ErrorLogger("Failed to generate %s FV file." %self.UiFvName)
return FvOutputFile