tiffany352 / rink-rs

Unit conversion tool and library written in rust

Home Page:https://rinkcalc.app/about

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Certain queries cause rink to hang

tiffany352 opened this issue · comments

  • Tim
  • Tm

certain variations are fine though:

  • Tim to ms
  • kTm
  • Tm to ms

happens in both web and cli

For me (on NixOS), not a hang but a stack overflow
❯ git rev-parse HEAD
4a492c64f33f51a89a685d31365042d21cb4f0ed
❯ rustc --version
rustc 1.72.1 (d5c2e9c34 2023-09-13)
❯ cargo r <<< kTm
    Finished dev [unoptimized + debuginfo] target(s) in 0.66s
warning: the following packages contain code that will be rejected by a future version of Rust: ubyte v0.10.1
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 1`
     Running `target/debug/rink`
2 minute, 53.61111 second (time)
❯ cargo r -q <<< Tim

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
zsh: abort (core dumped)  cargo r -q <<< Tim
❯ coredumpctl dump rink
           PID: 2089800 (rink)
           UID: 1000 (ag)
           GID: 100 (users)
        Signal: 6 (ABRT)
     Timestamp: Sat 2023-09-23 21:19:39 PDT (18s ago)
  Command Line: target/debug/rink
    Executable: /tmp/rink-rs/target/debug/rink
 Control Group: /user.slice/user-1000.slice/session-46.scope
          Unit: session-46.scope
         Slice: user-1000.slice
       Session: 46
     Owner UID: 1000 (ag)
       Boot ID: 6f9d3a176f324fb79b25c56acc661dfd
    Machine ID: <snip>
      Hostname: <snip>
       Storage: /var/lib/systemd/coredump/core.rink.1000.6f9d3a176f324fb79b25c56acc661dfd.2089800.1695529179000000.zst (present)
  Size on Disk: 1.2M
       Message: Process 2089800 (rink) of user 1000 dumped core.

                Module /tmp/rink-rs/target/debug/rink without build-id.
                Module /tmp/rink-rs/target/debug/rink
                Module libgcc_s.so.1 without build-id.
                Stack trace of thread 2089800:
                #0  0x00007ffff77c1a8c __pthread_kill_implementation (libc.so.6 + 0x87a8c)
                #1  0x00007ffff7772c86 raise (libc.so.6 + 0x38c86)
                #2  0x00007ffff775c8ba abort (libc.so.6 + 0x228ba)
                #3  0x000055555642b677 n/a (/tmp/rink-rs/target/debug/rink + 0xed7677)
                ELF object binary architecture: AMD x86-64

I assumed Tm was supposed to mean "terameters" until I read about Tims and thullium. What should rink do in this situation?

The issue turned out to be a stack overflow in the code that turns expressions into strings. The definition of Tim is 12^-4 hour and it was getting into infinite recursion on the -4 part. I'll put out a patch version soon with this fix included.