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.
This commit is contained in:
Mason Remaley 2025-02-26 14:53:14 -08:00 committed by mlugg
parent 06ee383da9
commit 87209954a7
No known key found for this signature in database
GPG key ID: 3F5B7DCCBF4AF02E
2 changed files with 2 additions and 1 deletions

View file

@ -2753,7 +2753,7 @@ pub fn saveZoirCache(cache_file: std.fs.File, stat: std.fs.File.Stat, zoir: Zoir
}, },
.{ .{
.base = @ptrCast(zoir.limbs), .base = @ptrCast(zoir.limbs),
.len = zoir.limbs.len * 4, .len = zoir.limbs.len * @sizeOf(std.math.big.Limb),
}, },
.{ .{
.base = zoir.string_bytes.ptr, .base = zoir.string_bytes.ptr,

View file

@ -234,6 +234,7 @@ pub fn updateFile(
error.FileTooBig => unreachable, // 0 is not too big error.FileTooBig => unreachable, // 0 is not too big
else => |e| return e, else => |e| return e,
}; };
try cache_file.seekTo(0);
if (stat.size > std.math.maxInt(u32)) if (stat.size > std.math.maxInt(u32))
return error.FileTooBig; return error.FileTooBig;