diff options
| author | David Rubin <daviru007@icloud.com> | 2024-12-26 03:05:49 -0800 |
|---|---|---|
| committer | David Rubin <87927264+Rexicon226@users.noreply.github.com> | 2025-02-25 11:22:33 -0800 |
| commit | 658fba982ce7280721e770df1d7ce4ab3f4eaf40 (patch) | |
| tree | 6c5ad38136062108e1d068a227447fdc22c6daa5 /lib | |
| parent | 590c613182d096e150dd9c882ab3bc6b20028011 (diff) | |
| download | zig-658fba982ce7280721e770df1d7ce4ab3f4eaf40.tar.gz zig-658fba982ce7280721e770df1d7ce4ab3f4eaf40.zip | |
ubsan: extend `ptr` before adding to avoid overflow
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ubsan.zig | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/lib/ubsan.zig b/lib/ubsan.zig index 0142adddc3..e7132aad98 100644 --- a/lib/ubsan.zig +++ b/lib/ubsan.zig @@ -1,5 +1,3 @@ -//! Minimal UBSan Runtime - const std = @import("std"); const builtin = @import("builtin"); const assert = std.debug.assert; @@ -471,7 +469,7 @@ fn floatCastOverflow( // See: https://github.com/llvm/llvm-project/blob/release/19.x/compiler-rt/lib/ubsan/ubsan_handlers.cpp#L463 // for more information on this check. const ptr: [*]const u8 = @ptrCast(data_handle); - if (ptr[0] + ptr[1] < 2 or ptr[0] == 0xFF or ptr[1] == 0xFF) { + if (@as(u16, ptr[0]) + @as(u16, ptr[1]) < 2 or ptr[0] == 0xFF or ptr[1] == 0xFF) { const data: *const FloatCastOverflowData = @ptrCast(data_handle); const from_value: Value = .{ .handle = from_handle, .type_descriptor = data.from }; logMessage("{} is outside the range of representable values of type {s}", .{ |
