zig
zig copied to clipboard
wrong line number in stack trace
Zig Version: 0.10.0-dev.3981+60678f5ba
Steps to reproduce:
const std = @import("std");
test {
var a: []const u8 = "My funny string";
var b: [128]u8 = undefined;
const key = [32]u8{ 0x13, 0x37, 0x99, 0x11, 0x11, 0x55, 0xFF, 0xAA, 0xBB, 0xCC, 0xFF, 0xBB, 0x13, 0x37, 0x99, 0x99, 0x13, 0x37, 0x99, 0x11, 0x11, 0x55, 0xFF, 0xAA, 0xBB, 0xCC, 0xFF, 0xBB, 0x13, 0x37, 0x99, 0x99 };
const nonce = [12]u8{ 0x13, 0x37, 0x99, 0x11, 0x11, 0x55, 0xFF, 0xAA, 0xBB, 0xCC, 0xFF, 0xBB };
std.crypto.stream.chacha.ChaCha8IETF.xor(b[0..], a[0..], 0, key, nonce);
}
[nix-shell:~/Downloads/zig/build]$ stage3/bin/zig test test.zig
Test [1/1] test_0... thread 469589 panic: reached unreachable code
/home/andy/Downloads/zig/lib/std/debug.zig:281:14: 0x20ffa6 in assert (test)
if (!ok) unreachable; // assertion failure
^
/home/andy/Downloads/zig/lib/std/crypto/chacha20.zig:394:19: 0x20f52a in xor (test)
pub fn xor(out: []u8, in: []const u8, counter: u32, key: [key_length]u8, nonce: [nonce_length]u8) void {
^
./test.zig:8:45: 0x20f4a4 in test_0 (test)
std.crypto.stream.chacha.ChaCha8IETF.xor(b[0..], a[0..], 0, key, nonce);
^
/home/andy/Downloads/zig/lib/test_runner.zig:79:28: 0x213165 in main (test)
} else test_fn.func();
^
/home/andy/Downloads/zig/lib/std/start.zig:568:22: 0x20ff4d in posixCallMainAndExit (test)
root.main();
^
/home/andy/Downloads/zig/lib/std/start.zig:340:5: 0x20f952 in _start (test)
@call(.{ .modifier = .never_inline }, posixCallMainAndExit, .{});
^
error: the following test command crashed:
zig-cache/o/4dc2fc2140133627808e3b17a79d727f/test /home/andy/Downloads/zig/build/stage3/bin/zig
The second frame points at xor but it should point at the next line, at
assert(in.len == out.len);
Duplicate/related #12725, stack trace points to correct line with this patch:
diff --git a/lib/std/crypto/chacha20.zig b/lib/std/crypto/chacha20.zig
index 2a43f4b94..2d9c67502 100644
--- a/lib/std/crypto/chacha20.zig
+++ b/lib/std/crypto/chacha20.zig
@@ -381,8 +381,7 @@ fn extend(key: [32]u8, nonce: [24]u8, comptime rounds_nb: usize) struct { key: [
};
}
-fn ChaChaIETF(comptime rounds_nb: usize) type {
- return struct {
+fn ChaChaIETF(comptime rounds_nb: usize) type { return struct {
/// Nonce length in bytes.
pub const nonce_length = 12;
/// Key length in bytes.
Thank you - I see that you have already a reduction and have narrowed down the problem to AstGen :+1: