jm / toml

Parse TOML. Like a bawss.
MIT License
151 stars 37 forks source link

Unexpected exceptions #76

Open mschwager opened 6 months ago

mschwager commented 6 months ago

Hi there,

I've been working on a new fuzzer for Ruby, and I used your library as a test harness. I was able to produce a few "unexpected" exceptions. In this situation, I consider "unexpected" to be parsing exceptions that don't produce a Parslet::ParseFailed.

So far, I've been able to produce two of these exceptions:

Running: crash-7f81bc60d0be53880f5202c85c82cf3eb1793808
/var/lib/gems/3.1.0/gems/toml-0.3.0/lib/toml/parser.rb:16:in `initialize': undefined method `each' for "# This )s a a\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5\\xD5# T\\xD5\\xD5\\xD5\\xD5\\xD5hi\\n"@0:Parslet::Slice (NoMethodError)

      parts.each do |part|
           ^^^^^

Reproducer: crash-7f81bc60d0be53880f5202c85c82cf3eb1793808.txt

Running: crash-d6206d938bb1d6b072c7495a43000312246e12c2
/var/lib/gems/3.1.0/gems/toml-0.3.0/lib/toml/transformer.rb:76:in `visit_array': Conflicting types in array: Integer, Integer, Array (RuntimeError)
    from /var/lib/gems/3.1.0/gems/toml-0.3.0/lib/toml/transformer.rb:69:in `block in visit_array'
    from /var/lib/gems/3.1.0/gems/toml-0.3.0/lib/toml/transformer.rb:69:in `map'
    from /var/lib/gems/3.1.0/gems/toml-0.3.0/lib/toml/transformer.rb:69:in `visit_array'
    from /var/lib/gems/3.1.0/gems/toml-0.3.0/lib/toml/transformer.rb:90:in `block in <class:Transformer>'
    from /var/lib/gems/3.1.0/gems/parslet-2.0.0/lib/parslet/transform.rb:217:in `instance_eval'
    from /var/lib/gems/3.1.0/gems/parslet-2.0.0/lib/parslet/transform.rb:217:in `call_on_match'
    from /var/lib/gems/3.1.0/gems/parslet-2.0.0/lib/parslet/transform.rb:235:in `block in transform_elt'
    from /var/lib/gems/3.1.0/gems/parslet-2.0.0/lib/parslet/transform.rb:232:in `each'
    from /var/lib/gems/3.1.0/gems/parslet-2.0.0/lib/parslet/transform.rb:232:in `transform_elt'
    from /var/lib/gems/3.1.0/gems/parslet-2.0.0/lib/parslet/transform.rb:185:in `apply'
    from /var/lib/gems/3.1.0/gems/parslet-2.0.0/lib/parslet/transform.rb:261:in `block in recurse_array'
    from /var/lib/gems/3.1.0/gems/parslet-2.0.0/lib/parslet/transform.rb:261:in `map'
    from /var/lib/gems/3.1.0/gems/parslet-2.0.0/lib/parslet/transform.rb:261:in `recurse_array'
    from /var/lib/gems/3.1.0/gems/parslet-2.0.0/lib/parslet/transform.rb:190:in `apply'
    from /var/lib/gems/3.1.0/gems/toml-0.3.0/lib/toml/parser.rb:11:in `initialize'

Reproducer: crash-d6206d938bb1d6b072c7495a43000312246e12c2.txt

These exceptions occur when running TOML::Parser.new(data).parsed against the data in the reproducer file.