tvix/eval: integer underflow when causing any kind of error in function passed to builtins.genList

#213
Opened by sterni at 2022-10-16T23·43+00

Also works if we use throw to cause the error:

> env RUST_BACKTRACE=1 cargo run -- -E 'builtins.genList (_: {}.foo) 1'
    Finished dev [unoptimized + debuginfo] target(s) in 0.12s
     Running `target/debug/tvix-eval -E 'builtins.genList (_: {}.foo) 1'`
thread 'main' panicked at 'attempt to subtract with overflow', src/vm.rs:165:22
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: tvix_eval::vm::VM::frame
             at ./src/vm.rs:165:22
   4: tvix_eval::vm::VM::chunk
             at ./src/vm.rs:169:10
   5: tvix_eval::vm::VM::current_span
             at ./src/vm.rs:198:9
   6: tvix_eval::vm::VM::force_for_output
             at ./src/vm.rs:856:17
   7: tvix_eval::vm::VM::force_for_output::{{closure}}
             at ./src/vm.rs:853:66
   8: core::iter::traits::iterator::Iterator::try_for_each::call::{{closure}}
             at /build/rustc-1.63.0-src/library/core/src/iter/traits/iterator.rs:2252:26
   9: core::iter::traits::iterator::Iterator::try_fold
             at /build/rustc-1.63.0-src/library/core/src/iter/traits/iterator.rs:2194:21
  10: core::iter::traits::iterator::Iterator::try_for_each
             at /build/rustc-1.63.0-src/library/core/src/iter/traits/iterator.rs:2255:9
  11: tvix_eval::vm::VM::force_for_output
             at ./src/vm.rs:853:34
  12: tvix_eval::vm::run_lambda
             at ./src/vm.rs:911:5
  13: tvix_eval::eval::interpret
             at ./src/eval.rs:139:9
  14: tvix_eval::main
             at ./src/main.rs:24:29
  15: core::ops::function::FnOnce::call_once
             at /build/rustc-1.63.0-src/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

  1. builtins.map is also affected, probably most call_with users except foldl' which seems to be fine.

    sterni at 2022-10-17T12·35+00

  2. Scratch that, calling is fine, the problem seems to lie in force_for_output when it encounters a thunk nested inside something:

    tvix-repl> [ (throw "lol") ]
    thread 'main' panicked at 'attempt to subtract with overflow', src/vm.rs:165:22
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    

    sterni at 2022-10-17T12·38+00

  3. Fixed in cl/7052, the commit message explains what's up.

    tazjin at 2022-10-21T14·05+00

  4. tazjin closed this issue at 2022-10-24T11·45+00