d0c-s4vage / gramfuzz

gramfuzz is a grammar-based fuzzer that lets one define complex grammars to generate text and binary data formats.
https://d0c-s4vage.github.io/gramfuzz/
MIT License
256 stars 39 forks source link

Error with `Int` field: doesn't respect min/max #33

Closed mgree closed 4 years ago

mgree commented 4 years ago

Checklist

Environment

Platform

Python Version

Describe the bug

Setting min and max doesn't seem to affect the Int field's behavior. The Int.build() method only checks to see whether min/max constrain a single value rather than using it has a general set of constraints.

To Reproduce

>>> from gramfuzz.fields import Int
>>> g = Int(min = 0, max=65535)
>>> g.build()
4038
>>> g.build()
-2592

Expected Behavior

I expect no values below min or above max to be generated.

Current Workaround

I use UInt with an explicit odds setting.

d0c-s4vage commented 4 years ago

Thanks for reporting this! This should be an easy one :^)

d0c-s4vage commented 4 years ago

Confirmed the issue, fixing...

d0c-s4vage commented 4 years ago

This was fixed in gramfuzz==1.3.2 pip install --upgrade gramfuzz (or pip3 install --upgrade gramfuzz) to get the fixes.

(venv)> pip install gramfuzz==1.3.2
...
(venv)> python
Python 3.6.8 (default, Apr  9 2019, 04:59:38) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from gramfuzz.fields import Int
>>> min = 0
>>> max = 65535
>>> g = Int(min=min, max=max)
>>> list(filter(lambda x: x < min and x > max, [g.build() for x in range(100000)]))
[]