Skip to content

panic handler crashes recursively with integer overflow #23527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gerwin3 opened this issue Apr 10, 2025 · 4 comments
Closed

panic handler crashes recursively with integer overflow #23527

gerwin3 opened this issue Apr 10, 2025 · 4 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@gerwin3
Copy link

gerwin3 commented Apr 10, 2025

Zig Version

0.14.0

Steps to Reproduce and Observed Behavior

In my library example (https://github.com/gerwin3/nvidia-video-codec-sdk/blob/main/examples/decode_rainbow.zig) if the code fails and returns an error then it does not produce a correct stack trace. The full output is:

error: InvalidValue
thread 31157 panic: integer overflow
aborting due to recursive panic
Aborted (core dumped)

I think it is because the stack trace function itself crashes at debug.zig:708.

try printSourceAtAddress(debug_info, out_stream, return_address - 1, tty_config);

So it seems when the return address is 0 the stack trace printing function fails. (I don't know how return address can be 0)

GDB stacktrace:

#0  0x00007ffff7c9916c in __pthread_kill_implementation () from /nix/store/rmy663w9p7xb202rcln4jjzmvivznmz8-glibc-2.40-66/lib/libc.so.6
#1  0x00007ffff7c40e86 in raise () from /nix/store/rmy663w9p7xb202rcln4jjzmvivznmz8-glibc-2.40-66/lib/libc.so.6
#2  0x00007ffff7c2893a in abort () from /nix/store/rmy663w9p7xb202rcln4jjzmvivznmz8-glibc-2.40-66/lib/libc.so.6
#3  0x000000000104d691 in posix.abort () at /nix/store/k8wr6zqyhchbnhy51r7f2l5fq14xl0zk-zig-0.14.0/lib/std/posix.zig:710
#4  0x0000000001048a77 in debug.defaultPanic (msg=..., first_trace_addr=...)
    at /nix/store/k8wr6zqyhchbnhy51r7f2l5fq14xl0zk-zig-0.14.0/lib/std/debug.zig:676
#5  0x00000000010437e9 in debug.FullPanic((function 'defaultPanic')).integerOverflow ()
    at /nix/store/k8wr6zqyhchbnhy51r7f2l5fq14xl0zk-zig-0.14.0/lib/std/debug.zig:91
#6  0x000000000106cdf6 in debug.writeStackTrace__anon_7169 (stack_trace=..., out_stream=..., debug_info=0x1135208 <debug.self_debug_info>, 
    tty_config=...) at /nix/store/k8wr6zqyhchbnhy51r7f2l5fq14xl0zk-zig-0.14.0/lib/std/debug.zig:708
#7  0x000000000104d803 in debug.dumpStackTrace (stack_trace=...) at /nix/store/k8wr6zqyhchbnhy51r7f2l5fq14xl0zk-zig-0.14.0/lib/std/debug.zig:501
#8  0x0000000001048e87 in debug.defaultPanic (msg=..., first_trace_addr=...)
    at /nix/store/k8wr6zqyhchbnhy51r7f2l5fq14xl0zk-zig-0.14.0/lib/std/debug.zig:659
#9  0x00000000010437e9 in debug.FullPanic((function 'defaultPanic')).integerOverflow ()
    at /nix/store/k8wr6zqyhchbnhy51r7f2l5fq14xl0zk-zig-0.14.0/lib/std/debug.zig:91
#10 0x000000000106cdf6 in debug.writeStackTrace__anon_7169 (stack_trace=..., out_stream=..., debug_info=0x1135208 <debug.self_debug_info>, 
    tty_config=...) at /nix/store/k8wr6zqyhchbnhy51r7f2l5fq14xl0zk-zig-0.14.0/lib/std/debug.zig:708
#11 0x000000000104d803 in debug.dumpStackTrace (stack_trace=...) at /nix/store/k8wr6zqyhchbnhy51r7f2l5fq14xl0zk-zig-0.14.0/lib/std/debug.zig:501
#12 0x00000000010f7fa6 in start.callMain () at /nix/store/k8wr6zqyhchbnhy51r7f2l5fq14xl0zk-zig-0.14.0/lib/std/start.zig:663
#13 start.callMainWithArgs () at /nix/store/k8wr6zqyhchbnhy51r7f2l5fq14xl0zk-zig-0.14.0/lib/std/start.zig:616
#14 start.main (c_argc=1, c_argv=0x7fffffffb768, c_envp=0x7fffffffb778)
    at /nix/store/k8wr6zqyhchbnhy51r7f2l5fq14xl0zk-zig-0.14.0/lib/std/start.zig:631

Expected Behavior

A stack trace to be there. No recursive panic.

@gerwin3 gerwin3 added the bug Observed behavior contradicts documented or intended behavior label Apr 10, 2025
@alexrp
Copy link
Member

alexrp commented Apr 10, 2025

What platform is this on?

@nektro
Copy link
Contributor

nektro commented Apr 10, 2025

x86_64 nixos linux

@gerwin3
Copy link
Author

gerwin3 commented Apr 11, 2025

Some extra information: After some debugging it turns out I had forgot to annotate some functions with callconv(C) that were loaded in dynamically (dlopen). Most likely the compiler crash has something to do with that. I could imagine the return address being incorrect when loading a function with the wrong callconv. Still would not expect the compiler to crash. Maybe a message like "return address incorrect"

@alexrp
Copy link
Member

alexrp commented Apr 11, 2025

This does not look like a compiler crash to me; it looks like a crash in your program. Violating calling convention can lead to all sorts of bugs, so I don't think there's a compiler issue here. Rather, it would be nice if someone could de-bitrot #19842.

@alexrp alexrp closed this as not planned Won't fix, can't repro, duplicate, stale Apr 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

3 participants