josefs / Gradualizer

A Gradual type system for Erlang
MIT License
613 stars 35 forks source link

An invalid utf32 value can crash eval_bits:eval_exp_field/6 #543

Open RobinMorisset opened 1 year ago

RobinMorisset commented 1 year ago

Running gradualizer on the following erlang code:

f() when binary_part(<<18446744073709551615/utf32>>, ok, ok) >= ok ->
    ok.

results in the following crash:

escript: exception error: construction of binary failed
  in function  eval_bits:eval_exp_field/6 (eval_bits.erl, line 153)
     *** segment 1 of type 'utf32': expected a non-negative integer encodable as utf32 but got: 18446744073709551615
  in call from eval_bits:create_binary/2 (eval_bits.erl, line 77)
  in call from eval_bits:expr_grp/5 (eval_bits.erl, line 68)
  in call from erl_eval:expr/6 (erl_eval.erl, line 543)
  in call from gradualizer_bin:bin_element_view/1 (src/gradualizer_bin.erl, line 43)
  in call from gradualizer_bin:'-bin_view/1-lc$^0/1-0-'/1 (src/gradualizer_bin.erl, line 35)
  in call from gradualizer_bin:bin_view/1 (src/gradualizer_bin.erl, line 35)