tree-sitter-grammars / tree-sitter-hcl

HCL grammar for tree-sitter
https://tree-sitter-grammars.github.io/tree-sitter-hcl/
Apache License 2.0
92 stars 20 forks source link

Infinite loop on fuzzing input #49

Open MichaHoffmann opened 2 months ago

MichaHoffmann commented 2 months ago

Describe the bug The parser can produce an infinite loop on some inputs.

To Reproduce loop.hcl:

-+-*a(//

leads to:

tree-sitter parse oom.hcl --wasm --debug
...
process version:4, version_count:6, state:554, row:0, col:8
lex_internal state:0, row:0, column:8
lexed_lookahead sym:end, size:0
detect_error
process version:5, version_count:6, state:175, row:0, col:8
reduce sym:variable_expr, child_count:1
reduce sym:binary_operation, child_count:3
reduce sym:operation, child_count:1
reduce sym:binary_operation, child_count:3
reduce sym:operation, child_count:1
reduce sym:expression, child_count:1
detect_error
resume version:0
recover_with_missing symbol:.*, state:139
recover_to_previous state:175, depth:3
condense
process version:1, version_count:6, state:139, row:0, col:8
reduce sym:attr_splat, child_count:1
reduce sym:splat, child_count:1
reduce sym:_expr_term, child_count:2
detect_error
process version:2, version_count:6, state:129, row:0, col:8
reduce sym:expression, child_count:1
detect_error
process version:3, version_count:6, state:407, row:0, col:8
lex_internal state:0, row:0, column:8
lexed_lookahead sym:end, size:0
detect_error
...
loops here endlessly

Expected behavior A quick parse with error output.

Additional context Found using fuzzing.

tree-sitter --version
tree-sitter 0.22.6 (b40f342067a89cd6331bf4c27407588320f3c263)