From 87209954a74bbf9b82b7ab24c0389a4a133edd31 Mon Sep 17 00:00:00 2001 From: Mason Remaley Date: Wed, 26 Feb 2025 14:53:14 -0800 Subject: [PATCH] Zcu: fix ZOIR cache bugs * When saving bigint limbs, we gave the iovec the wrong length, meaning bigint data (and the following string and compile error data) was corrupted. * When updating a stale ZOIR cache, we failed to truncate the file, so just wrote more bytes onto the end of the stale cache. --- src/Zcu.zig | 2 +- src/Zcu/PerThread.zig | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Zcu.zig b/src/Zcu.zig index 267551cb3432c10e89918a1efe49b4739aecba80..1486be6746ff523e5ec2971974447cd949b5dbb9 100644 --- a/src/Zcu.zig +++ b/src/Zcu.zig @@ -2753,7 +2753,7 @@ pub fn saveZoirCache(cache_file: std.fs.File, stat: std.fs.File.Stat, zoir: Zoir }, .{ .base = @ptrCast(zoir.limbs), - .len = zoir.limbs.len * 4, + .len = zoir.limbs.len * @sizeOf(std.math.big.Limb), }, .{ .base = zoir.string_bytes.ptr, diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index 1031ee6c5466efad14203907a36b96028e4e6581..095cd6c1cbd6c3f86d9c61e63995e85630e6581d 100644 --- a/src/Zcu/PerThread.zig +++ b/src/Zcu/PerThread.zig @@ -234,6 +234,7 @@ pub fn updateFile( error.FileTooBig => unreachable, // 0 is not too big else => |e| return e, }; + try cache_file.seekTo(0); if (stat.size > std.math.maxInt(u32)) return error.FileTooBig; -- 2.54.0