1. Make code alignment as 4 byte indent.
authorlgao4 <lgao4@7335b38e-4728-0410-8992-fb3ffe349368>
Tue, 20 Oct 2009 06:00:40 +0000 (06:00 +0000)
committerlgao4 <lgao4@7335b38e-4728-0410-8992-fb3ffe349368>
Tue, 20 Oct 2009 06:00:40 +0000 (06:00 +0000)
2. Add check for the size of each FV extend entry, which can't exceed 0x10000.

git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1723 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/GenFds/Fv.py

index ca32bd6..a9ff26e 100644 (file)
@@ -221,77 +221,76 @@ class FV (FvClassObject):
         # Generate FV extension header file\r
         #\r
         if self.FvNameGuid == None or self.FvNameGuid == '':\r
-          if len(self.FvExtEntryType) > 0:\r
-            GenFdsGlobalVariable.ErrorLogger("FV Extension Header Entries declared for %s with no FvNameGuid declaration." % (self.UiFvName))\r
+            if len(self.FvExtEntryType) > 0:\r
+                GenFdsGlobalVariable.ErrorLogger("FV Extension Header Entries declared for %s with no FvNameGuid declaration." % (self.UiFvName))\r
         \r
         if self.FvNameGuid <> None and self.FvNameGuid <> '':\r
-          TotalSize = 16 + 4\r
-          Buffer = ''\r
-          for Index in range (0, len(self.FvExtEntryType)):\r
-            if self.FvExtEntryType[Index] == 'FILE':\r
-            \r
-              # check if the path is absolute or relative
-              if os.path.isabs(self.FvExtEntryData[Index]):
-                  FileFullPath = os.path.normpath(self.FvExtEntryData[Index])
-              else:
-                  FileFullPath = os.path.normpath(os.path.join(GenFdsGlobalVariable.WorkSpaceDir, self.FvExtEntryData[Index]))
-
-              # check if the file path exists or not
-              if not os.path.isfile(FileFullPath):
-                  GenFdsGlobalVariable.ErrorLogger("Error opening FV Extension Header Entry file %s." % (self.FvExtEntryData[Index]))\r
-                  \r
-              FvExtFile = open (FileFullPath,'rb')\r
-              FvExtFile.seek(0,2)\r
-              Size = FvExtFile.tell()\r
-              TotalSize += (Size + 4)\r
-              FvExtFile.seek(0)\r
-              Buffer += pack('HH', (Size + 4), int(self.FvExtEntryTypeValue[Index], 16))\r
-              Buffer += FvExtFile.read() \r
-              FvExtFile.close()\r
-            if self.FvExtEntryType[Index] == 'DATA':\r
-              ByteList = self.FvExtEntryData[Index].split(',')\r
-              Size = len (ByteList)\r
-              TotalSize += (Size + 4)\r
-              Buffer += pack('HH', (Size + 4), int(self.FvExtEntryTypeValue[Index], 16))\r
-              for Index1 in range (0, Size):\r
-                Buffer += pack('B', int(ByteList[Index1], 16))\r
-          Guid = self.FvNameGuid.split('-')\r
-          Buffer = pack('LHHBBBBBBBBL', \r
-                      int(Guid[0], 16), \r
-                      int(Guid[1], 16), \r
-                      int(Guid[2], 16), \r
-                      int(Guid[3][-4:-2], 16), \r
-                      int(Guid[3][-2:], 16),  \r
-                      int(Guid[4][-12:-10], 16),\r
-                      int(Guid[4][-10:-8], 16),\r
-                      int(Guid[4][-8:-6], 16),\r
-                      int(Guid[4][-6:-4], 16),\r
-                      int(Guid[4][-4:-2], 16),\r
-                      int(Guid[4][-2:], 16),\r
-                      TotalSize\r
-                      ) + Buffer\r
+            TotalSize = 16 + 4\r
+            Buffer = ''\r
+            for Index in range (0, len(self.FvExtEntryType)):\r
+                if self.FvExtEntryType[Index] == 'FILE':\r
+                    # check if the path is absolute or relative
+                    if os.path.isabs(self.FvExtEntryData[Index]):
+                        FileFullPath = os.path.normpath(self.FvExtEntryData[Index])
+                    else:
+                        FileFullPath = os.path.normpath(os.path.join(GenFdsGlobalVariable.WorkSpaceDir, self.FvExtEntryData[Index]))
+                    # check if the file path exists or not
+                    if not os.path.isfile(FileFullPath):
+                        GenFdsGlobalVariable.ErrorLogger("Error opening FV Extension Header Entry file %s." % (self.FvExtEntryData[Index]))\r
+                    FvExtFile = open (FileFullPath,'rb')\r
+                    FvExtFile.seek(0,2)\r
+                    Size = FvExtFile.tell()\r
+                    if Size >= 0x10000:\r
+                        GenFdsGlobalVariable.ErrorLogger("The size of FV Extension Header Entry file %s exceeds 0x10000." % (self.FvExtEntryData[Index]))\r
+                    TotalSize += (Size + 4)\r
+                    FvExtFile.seek(0)\r
+                    Buffer += pack('HH', (Size + 4), int(self.FvExtEntryTypeValue[Index], 16))\r
+                    Buffer += FvExtFile.read() \r
+                    FvExtFile.close()\r
+                if self.FvExtEntryType[Index] == 'DATA':\r
+                    ByteList = self.FvExtEntryData[Index].split(',')\r
+                    Size = len (ByteList)\r
+                    if Size >= 0x10000:\r
+                        GenFdsGlobalVariable.ErrorLogger("The size of FV Extension Header Entry data %s exceeds 0x10000." % (self.FvExtEntryData[Index]))\r
+                    TotalSize += (Size + 4)\r
+                    Buffer += pack('HH', (Size + 4), int(self.FvExtEntryTypeValue[Index], 16))\r
+                    for Index1 in range (0, Size):\r
+                        Buffer += pack('B', int(ByteList[Index1], 16))\r
 \r
-          #\r
-          # Generate FV extension header file if the total size is not zero\r
-          #\r
-          if TotalSize <> 0:                    \r
-            FvExtHeaderFileName = os.path.join(GenFdsGlobalVariable.FvDir, self.UiFvName + '.ext')\r
-            FvExtHeaderFile = open (FvExtHeaderFileName,'wb')\r
-            FvExtHeaderFile.write(Buffer)\r
-            FvExtHeaderFile.close()\r
-            self.FvInfFile.writelines("EFI_FV_EXT_HEADER_FILE_NAME = "      + \\r
-                                       FvExtHeaderFileName                  + \\r
-                                       T_CHAR_LF)\r
-       \r
+            Guid = self.FvNameGuid.split('-')\r
+            Buffer = pack('LHHBBBBBBBBL', \r
+                        int(Guid[0], 16), \r
+                        int(Guid[1], 16), \r
+                        int(Guid[2], 16), \r
+                        int(Guid[3][-4:-2], 16), \r
+                        int(Guid[3][-2:], 16),  \r
+                        int(Guid[4][-12:-10], 16),\r
+                        int(Guid[4][-10:-8], 16),\r
+                        int(Guid[4][-8:-6], 16),\r
+                        int(Guid[4][-6:-4], 16),\r
+                        int(Guid[4][-4:-2], 16),\r
+                        int(Guid[4][-2:], 16),\r
+                        TotalSize\r
+                        ) + Buffer\r
+\r
+            #\r
+            # Generate FV extension header file if the total size is not zero\r
+            #\r
+            if TotalSize > 0:\r
+                FvExtHeaderFileName = os.path.join(GenFdsGlobalVariable.FvDir, self.UiFvName + '.ext')\r
+                FvExtHeaderFile = open (FvExtHeaderFileName,'wb')\r
+                FvExtHeaderFile.write(Buffer)\r
+                FvExtHeaderFile.close()\r
+                self.FvInfFile.writelines("EFI_FV_EXT_HEADER_FILE_NAME = "      + \\r
+                                           FvExtHeaderFileName                  + \\r
+                                           T_CHAR_LF)\r
 \r
+         \r
         #\r
         # Add [Files]\r
         #\r
-\r
         self.FvInfFile.writelines("[files]" + T_CHAR_LF)\r
         if VtfDict != None and self.UiFvName in VtfDict.keys():\r
             self.FvInfFile.writelines("EFI_FILE_NAME = "                   + \\r
                                        VtfDict.get(self.UiFvName)          + \\r
                                        T_CHAR_LF)\r
-\r
-\r