authorgravatar for gereeter+code@gmail.comJonathan S <gereeter+code@gmail.com> 2021-12-21 13:11:14-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-31 14:20:02-07:00
logf5cb3fc688768edea283f497a31e714ad387c207
tree66d8eb9d6f77a54eab59d3cebdbb81ea5dd7380e
parentacdb859644be344f5e62578ad19a699d94a642a6

Only check the file's length once in pdb.Msf.init


1 files changed, 3 insertions(+), 2 deletions(-)

lib/std/pdb.zig+3-2
...@@ -868,7 +868,8 @@ const Msf = struct {...@@ -868,7 +868,8 @@ const Msf = struct {
868 return error.InvalidDebugInfo;868 return error.InvalidDebugInfo;
869 if (superblock.FreeBlockMapBlock != 1 and superblock.FreeBlockMapBlock != 2)869 if (superblock.FreeBlockMapBlock != 1 and superblock.FreeBlockMapBlock != 2)
870 return error.InvalidDebugInfo;870 return error.InvalidDebugInfo;
871 if (superblock.NumBlocks * superblock.BlockSize != try file.getEndPos())871 const file_len = try file.getEndPos();
872 if (superblock.NumBlocks * superblock.BlockSize != file_len)
872 return error.InvalidDebugInfo;873 return error.InvalidDebugInfo;
873 switch (superblock.BlockSize) {874 switch (superblock.BlockSize) {
874 // llvm only supports 4096 but we can handle any of these values875 // llvm only supports 4096 but we can handle any of these values
...@@ -919,7 +920,7 @@ const Msf = struct {...@@ -919,7 +920,7 @@ const Msf = struct {
919 const block_id = try directory.reader().readIntLittle(u32);920 const block_id = try directory.reader().readIntLittle(u32);
920 const n = (block_id % superblock.BlockSize);921 const n = (block_id % superblock.BlockSize);
921 // 0 is for SuperBlock, 1 and 2 for FPMs.922 // 0 is for SuperBlock, 1 and 2 for FPMs.
922 if (block_id == 0 or n == 1 or n == 2 or block_id * superblock.BlockSize > try file.getEndPos())923 if (block_id == 0 or n == 1 or n == 2 or block_id * superblock.BlockSize > file_len)
923 return error.InvalidBlockIndex;924 return error.InvalidBlockIndex;
924 blocks[j] = block_id;925 blocks[j] = block_id;
925 }926 }