ronin-rb / ronin-fuzzer

A Ruby library for generating, mutating, and fuzzing data
https://ronin-rb.dev
GNU Lesser General Public License v3.0
11 stars 3 forks source link

Template: Enumerator::ArithmeticSequence support for length #16

Open noraj opened 1 year ago

noraj commented 1 year ago

This example is on the documentation but currently doesn't work

https://github.com/noraj/ronin-fuzzer/blob/e398afb5020eb37c6b94db1b1e1b5ff2a8921a07/lib/ronin/fuzzing/core_ext/string.rb#L81-L84

irb(main):067:1* String.generate(['/AA', (1..100).step(5)]) do |path|
irb(main):068:1*   puts path
irb(main):069:0> end
/home/noraj/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/ronin-fuzzer-0.1.0/lib/ronin/fuzzing/template.rb:86:in `block in initialize': length must be an Integer, Range or Array (TypeError)

            raise(TypeError,"length must be an Integer, Range or Array")
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        from /home/noraj/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/ronin-fuzzer-0.1.0/lib/ronin/fuzzing/template.rb:54:in `each'
        from /home/noraj/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/ronin-fuzzer-0.1.0/lib/ronin/fuzzing/template.rb:54:in `initialize'
        from /home/noraj/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/ronin-fuzzer-0.1.0/lib/ronin/fuzzing/core_ext/string.rb:89:in `new'
        from /home/noraj/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/ronin-fuzzer-0.1.0/lib/ronin/fuzzing/core_ext/string.rb:89:in `generate'
        from (irb):67:in `<main>'
        from /home/noraj/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
        from /home/noraj/.asdf/installs/ruby/3.2.2/bin/irb:25:in `load'
        from /home/noraj/.asdf/installs/ruby/3.2.2/bin/irb:25:in `<main>'
irb(main):070:0> (1..100).step(5).class
=> Enumerator::ArithmeticSequence
irb(main):071:0> (1..100).class
=> Range
noraj commented 1 year ago

Maybe this fix should not be only for Enumerator::ArithmeticSequence but to more generic enumerators. However, I'm not sure of the consequences of a broader change.

postmodern commented 1 year ago

We could also support Enumerable. It appears that Ronin::Fuzzing::Repeater#initialize accepts an Enumerable lengths value.

Also, this definitely needs a test.