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 {
868868 return error.InvalidDebugInfo;
869869 if (superblock.FreeBlockMapBlock != 1 and superblock.FreeBlockMapBlock != 2)
870870 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)
872873 return error.InvalidDebugInfo;
873874 switch (superblock.BlockSize) {
874875 // llvm only supports 4096 but we can handle any of these values
......@@ -919,7 +920,7 @@ const Msf = struct {
919920 const block_id = try directory.reader().readIntLittle(u32);
920921 const n = (block_id % superblock.BlockSize);
921922 // 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)
923924 return error.InvalidBlockIndex;
924925 blocks[j] = block_id;
925926 }