Skip to content

panic handler crashes recursively with integer overflow #23527

Description

@gerwin3

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.

tryprintSourceAtAddress(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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions