REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2310
When target FV 99% used and only few bytes space left,
SplitFspBin.py may crash with below error:
File "SplitFspBin.py", line 457, in ParseFv
ffshdr = EFI_FFS_FILE_HEADER.from_buffer (self.FvData, offset)
ValueError: Buffer size too small
(40960 instead of at least 40968 bytes)
It was because the offset used by FFS_HEADER parser out of bounds.
It should stop parsing when offset equal or larger than
(buffer size - FFS_HEADER size).
This patch also fixed another crash issue when running script with
Python 3.x and no input parameter given:
File "SplitFspBin.py", line 868, in main
if args.which in ['rebase', 'split', 'genhdr', 'info']:
AttributeError: 'Namespace' object has no attribute 'which'
Test:
1. Ran script with both py2 and py3 with no input and no crash observed.
2. Compare the script result before and after the patch are identical.
Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Signed-off-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
ffssize = len(self.FfsData)\r
offset = sizeof(self.FfsHdr)\r
if self.FfsHdr.Name != '\xff' * 16:\r
ffssize = len(self.FfsData)\r
offset = sizeof(self.FfsHdr)\r
if self.FfsHdr.Name != '\xff' * 16:\r
- while offset < ffssize:\r
+ while offset < (ffssize - sizeof (EFI_COMMON_SECTION_HEADER)):\r
sechdr = EFI_COMMON_SECTION_HEADER.from_buffer (self.FfsData, offset)\r
sec = Section (offset, self.FfsData[offset:offset + int(sechdr.Size)])\r
self.SecList.append(sec)\r
sechdr = EFI_COMMON_SECTION_HEADER.from_buffer (self.FfsData, offset)\r
sec = Section (offset, self.FfsData[offset:offset + int(sechdr.Size)])\r
self.SecList.append(sec)\r
else:\r
offset = self.FvHdr.HeaderLength\r
offset = AlignPtr(offset)\r
else:\r
offset = self.FvHdr.HeaderLength\r
offset = AlignPtr(offset)\r
- while offset < fvsize:\r
+ while offset < (fvsize - sizeof (EFI_FFS_FILE_HEADER)):\r
ffshdr = EFI_FFS_FILE_HEADER.from_buffer (self.FvData, offset)\r
if (ffshdr.Name == '\xff' * 16) and (int(ffshdr.Size) == 0xFFFFFF):\r
offset = fvsize\r
ffshdr = EFI_FFS_FILE_HEADER.from_buffer (self.FvData, offset)\r
if (ffshdr.Name == '\xff' * 16) and (int(ffshdr.Size) == 0xFFFFFF):\r
offset = fvsize\r
offset = 0\r
fdsize = len(self.FdData)\r
self.FvList = []\r
offset = 0\r
fdsize = len(self.FdData)\r
self.FvList = []\r
- while offset < fdsize:\r
+ while offset < (fdsize - sizeof (EFI_FIRMWARE_VOLUME_HEADER)):\r
fvh = EFI_FIRMWARE_VOLUME_HEADER.from_buffer (self.FdData, offset)\r
if b'_FVH' != fvh.Signature:\r
raise Exception("ERROR: Invalid FV header !")\r
fvh = EFI_FIRMWARE_VOLUME_HEADER.from_buffer (self.FdData, offset)\r
if b'_FVH' != fvh.Signature:\r
raise Exception("ERROR: Invalid FV header !")\r
\r
def main ():\r
parser = argparse.ArgumentParser()\r
\r
def main ():\r
parser = argparse.ArgumentParser()\r
- subparsers = parser.add_subparsers(title='commands')\r
+ subparsers = parser.add_subparsers(title='commands', dest="which")\r
\r
parser_rebase = subparsers.add_parser('rebase', help='rebase a FSP into a new base address')\r
parser_rebase.set_defaults(which='rebase')\r
\r
parser_rebase = subparsers.add_parser('rebase', help='rebase a FSP into a new base address')\r
parser_rebase.set_defaults(which='rebase')\r
elif args.which == 'info':\r
ShowFspInfo (args.FspBinary)\r
else:\r
elif args.which == 'info':\r
ShowFspInfo (args.FspBinary)\r
else:\r