Modernize a bit the pygments fuzzer (#7382)

- Use atheris.instrument_all(), since pygments uses a custom importer
- Get rid of the useless main(), to make the two fuzzers similar
- Narrow an expected exception type

Co-authored-by: Julien Voisin <jvoisin@google.com>
This commit is contained in:
Julien Voisin 2022-03-14 18:41:42 +01:00 committed by GitHub
parent aa99b6f760
commit 4e962ea940
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 18 deletions

View File

@ -15,24 +15,20 @@
# limitations under the License.
import atheris
with atheris.instrument_imports():
import sys
import pygments
import pygments.lexers
@atheris.instrument_func
import sys
import pygments
import pygments.lexers
import pygments.util
def TestOneInput(data: bytes) -> int:
try:
lexer = pygments.lexers.guess_lexer(str(data))
except ValueError:
except pygments.util.ClassNotFound:
return 0
return 0
def main():
atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True)
atheris.Fuzz()
if __name__ == "__main__":
main()
atheris.instrument_all()
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()

View File

@ -15,11 +15,11 @@
# limitations under the License.
import atheris
with atheris.instrument_imports():
import sys
import pygments
import pygments.formatters.html
import pygments.lexers
import sys
import pygments
import pygments.formatters.html
import pygments.lexers
formatter = pygments.formatters.html.HtmlFormatter()
# pygments.LEXERS.values() is a list of tuples like this, with some of then empty:
@ -36,5 +36,6 @@ def TestOneInput(data: bytes) -> int:
return 0
atheris.instrument_all()
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()