jaq icon indicating copy to clipboard operation
jaq copied to clipboard

Stack overflow when recursively assigning something with iterable values

Open wader opened this issue 1 year ago • 1 comments

$ jq -cn '1 | .. = [.]'
[1]

$ cargo run -- -cn '1 | .. = [.]'
thread 'main' has overflowed its stack
fatal runtime error: stack overflow

$ cargo run -- -n '1 | .. = [2]'
thread 'main' has overflowed its stack
fatal runtime error: stack overflow

$ cargo run -- -n '1 | .. = []'
[]

wader avatar Nov 14 '24 22:11 wader

@itchyny has already brought this up in #139.

TL;DR: The update behaviour for .. can yield unexpected results for both jq and jaq (they're just more visible in jaq). Instead of .. |= f, I recommend defining def recurse_up: (.[]? | recurse_up), .; and using recurse_up |= f instead.

01mf02 avatar Nov 15 '24 09:11 01mf02

I addressed this in #285.

01mf02 avatar Jul 15 '25 07:07 01mf02