Error handling for some strange NoneType errors

Currently it seems like a top level argument node can be created. Need to check that soon, but not tonight. I am tired

Took 38 minutes
This commit is contained in:
ayrton 2023-11-22 20:33:34 -07:00
parent 1da53dba48
commit be30f1d264
5 changed files with 642 additions and 6 deletions

View file

@ -1,5 +1,6 @@
import xml
import xml.dom.minidom
import xml.etree.ElementTree as ET
from abc import ABC, abstractmethod
from constants import *
@ -107,7 +108,11 @@ class GeneralUnparser:
self.unparse_brackets(node)
elif node.tag == GAZ_BREAK_TAG:
self.unparse_break(node)
elif node.tag is None:
raise NoneTagException("None tag encountered", self.xml)
else:
with open("unknown_tag.xml", "w") as f:
f.write(self.pretty_xml())
raise Exception("Unknown tag: " + node.tag)
def unparse_block(self, node):
@ -319,4 +324,7 @@ class GeneralUnparser:
def format_single_arg(self, param, param1):
raise NotImplementedError
def pretty_xml(self):
dom = xml.dom.minidom.parseString(ET.tostring(self.xml).decode('utf-8'))
pretty: str = dom.toprettyxml()
return pretty

View file

@ -47,3 +47,11 @@ GAZ_STRING_KEY = "string"
GAZ_CHAR_KEY = "char"
GAZ_BRACKET_TAG = "brackets"
GAZ_BREAK_TAG = "break"
class NoneTagException(Exception):
def __init__(self, message, xml):
super().__init__(message)
self.xml = xml

View file

@ -33,7 +33,10 @@ class GazpreaFuzzer:
self.write_ast() # FIXME sometimes this is none
self.gaz_source_gen = GazUnparser(self.generator.ast, True)
self.gaz_source_gen.unparse()
try:
self.gaz_source_gen.unparse()
except NoneTagException as n:
raise NoneTagException("", n.xml)
self.ast = self.generator.ast
self.source = self.gaz_source_gen.source
@ -55,6 +58,6 @@ class GazpreaFuzzer:
pretty: str = dom.toprettyxml()
randint = random.randint(0, 1000)
print(randint)
print(randint, file=sys.stderr)
with open("debug/ast/debug_{}.xml".format(randint), 'w') as f:
f.write(pretty)

View file

@ -1,5 +1,6 @@
import os
import random
import warnings
from contextlib import redirect_stdout
import yaml
@ -10,6 +11,9 @@ import argparse
import xml.dom.minidom
import xml.etree.ElementTree as ET
from constants import NoneTagException
class Fuzzer():
def __init__(self, config: str, batch: int, seed: str, file_name: str = "fuzz"):
with open(config) as yaml_file:
@ -26,11 +30,21 @@ class Fuzzer():
os.mkdir("fuzzer")
os.mkdir("fuzzer/input")
os.mkdir("fuzzer/debug")
os.mkdir("fuzzer/debug/ast")
os.mkdir("fuzzer/instream")
os.mkdir("fuzzer/outputs")
os.mkdir("fuzzer/ground_truth")
for i in range(self.batch):
self.fuzzer.fuzz()
try:
self.fuzzer.fuzz()
except NoneTagException as n:
r = random.randint(0, 1000000)
warnings.warn("None Tag Exception encountered, writing stack trace and xml to debug/ast/{}.xml\n"
"Look for a top-level <argument> tag or send it to Ayrton and I'll see what I can see"
"".format(r))
with open("fuzzer/debug/ast/{}.xml".format(r), 'w') as f:
f.write(xml.dom.minidom.parseString(ET.tostring(self.fuzzer.ast).decode('utf-8')).toprettyxml())
continue
dom = xml.dom.minidom.parseString(ET.tostring(self.fuzzer.ast).decode('utf-8'))
pretty: str = dom.toprettyxml()
@ -41,7 +55,7 @@ class Fuzzer():
with redirect_stdout(y): # Workaround for fuzzer.py:49
try:
exec(f.read(), globals(), locals())
except OverflowError:
except (OverflowError, ZeroDivisionError):
os.system("rm -f fuzzer/ground_truth/{}_{}.py".format(self.file_name, i))
continue
with open("fuzzer/input/{}_{}.in".format(self.file_name, i), 'w') as f:

603
unknown_tag.xml Normal file
View file

@ -0,0 +1,603 @@
<?xml version="1.0" ?>
<block>
<procedure name="main" return_type="int" args="()">
<block>
<declaration type="int">
<variable name="Mosur" type="int" mut="var"/>
<rhs>
<operator op="addition" type="int">
<lhs>
<brackets type="int">
<rhs>
<operator op="addition" type="int">
<lhs>
<operator op="multiplication" type="int">
<lhs>
<operator op="multiplication" type="int">
<lhs>
<literal type="int" value="964"/>
</lhs>
<rhs>
<literal type="int" value="174"/>
</rhs>
</operator>
</lhs>
<rhs>
<operator op="subtraction" type="int">
<lhs>
<literal type="int" value="354"/>
</lhs>
<rhs>
<literal type="int" value="-568"/>
</rhs>
</operator>
</rhs>
</operator>
</lhs>
<rhs>
<operator op="subtraction" type="int">
<lhs>
<brackets type="int">
<rhs>
<literal type="int" value="-226"/>
</rhs>
</brackets>
</lhs>
<rhs>
<brackets type="int">
<rhs>
<literal type="int" value="-405"/>
</rhs>
</brackets>
</rhs>
</operator>
</rhs>
</operator>
</rhs>
</brackets>
</lhs>
<rhs>
<brackets type="int">
<rhs>
<unary op="noop" type="int">
<rhs>
<literal type="int" value="-448"/>
</rhs>
</unary>
</rhs>
</brackets>
</rhs>
</operator>
</rhs>
</declaration>
<return type="int">
<literal type="int" value="0"/>
</return>
</block>
</procedure>
<argument name="joree" type="int"/>
<block>
<stream type="std_output">
<unary op="noop" type="int">
<rhs>
<operator op="addition" type="int">
<lhs>
<literal type="int" value="-805"/>
</lhs>
<rhs>
<brackets type="int">
<rhs>
<brackets type="int">
<rhs>
<operator op="modulo" type="int">
<lhs>
<literal type="int" value="-478"/>
</lhs>
<rhs>
<literal type="int" value="-61"/>
</rhs>
</operator>
</rhs>
</brackets>
</rhs>
</brackets>
</rhs>
</operator>
</rhs>
</unary>
</stream>
<return type="int">
<operator op="addition" type="int">
<lhs>
<literal type="int" value="119"/>
</lhs>
<rhs>
<brackets type="int">
<rhs>
<brackets type="int">
<rhs>
<literal type="int" value="852"/>
</rhs>
</brackets>
</rhs>
</brackets>
</rhs>
</operator>
</return>
</block>
<function name="bendy" return_type="int">
<argument name="campo" type="int"/>
<block>
<stream type="std_output">
<operator op="subtraction" type="int">
<lhs>
<literal type="int" value="182"/>
</lhs>
<rhs>
<brackets type="int">
<rhs>
<operator op="power" type="int">
<lhs>
<literal type="int" value="-447"/>
</lhs>
<rhs>
<unary op="noop" type="int">
<rhs>
<operator op="addition" type="int">
<lhs>
<literal type="int" value="539"/>
</lhs>
<rhs>
<literal type="int" value="-674"/>
</rhs>
</operator>
</rhs>
</unary>
</rhs>
</operator>
</rhs>
</brackets>
</rhs>
</operator>
</stream>
<return type="int">
<operator op="subtraction" type="int">
<lhs>
<unary op="noop" type="int">
<rhs>
<operator op="multiplication" type="int">
<lhs>
<operator op="addition" type="int">
<lhs>
<operator op="division" type="int">
<lhs>
<literal type="int" value="-623"/>
</lhs>
<rhs>
<literal type="int" value="233"/>
</rhs>
</operator>
</lhs>
<rhs>
<literal type="int" value="84"/>
</rhs>
</operator>
</lhs>
<rhs>
<operator op="addition" type="int">
<lhs>
<unary op="noop" type="int">
<rhs>
<literal type="int" value="-760"/>
</rhs>
</unary>
</lhs>
<rhs>
<operator op="power" type="int">
<lhs>
<literal type="int" value="-262"/>
</lhs>
<rhs>
<literal type="int" value="940"/>
</rhs>
</operator>
</rhs>
</operator>
</rhs>
</operator>
</rhs>
</unary>
</lhs>
<rhs>
<operator op="addition" type="int">
<lhs>
<operator op="subtraction" type="int">
<lhs>
<operator op="addition" type="int">
<lhs>
<brackets type="int">
<rhs>
<literal type="int" value="-407"/>
</rhs>
</brackets>
</lhs>
<rhs>
<operator op="multiplication" type="int">
<lhs>
<literal type="int" value="-132"/>
</lhs>
<rhs>
<literal type="int" value="517"/>
</rhs>
</operator>
</rhs>
</operator>
</lhs>
<rhs>
<operator op="addition" type="int">
<lhs>
<operator op="addition" type="int">
<lhs>
<literal type="int" value="557"/>
</lhs>
<rhs>
<literal type="int" value="-795"/>
</rhs>
</operator>
</lhs>
<rhs>
<literal type="int" value="286"/>
</rhs>
</operator>
</rhs>
</operator>
</lhs>
<rhs>
<operator op="addition" type="int">
<lhs>
<operator op="addition" type="int">
<lhs>
<literal type="int" value="-547"/>
</lhs>
<rhs>
<operator op="multiplication" type="int">
<lhs>
<literal type="int" value="-841"/>
</lhs>
<rhs>
<literal type="int" value="-660"/>
</rhs>
</operator>
</rhs>
</operator>
</lhs>
<rhs>
<operator op="division" type="int">
<lhs>
<brackets type="int">
<rhs>
<literal type="int" value="399"/>
</rhs>
</brackets>
</lhs>
<rhs>
<literal type="int" value="-750"/>
</rhs>
</operator>
</rhs>
</operator>
</rhs>
</operator>
</rhs>
</operator>
</return>
</block>
</function>
<procedure name="ghazi" return_type="int">
<argument name="chapt" type="int"/>
<argument name="nasal" type="int"/>
<argument name="thiol" type="int"/>
<argument name="hypho" type="int"/>
<argument name="remit" type="int"/>
<argument name="rebia" type="int"/>
<block>
<stream type="std_output">
<brackets type="int">
<rhs>
<unary op="noop" type="int">
<rhs>
<operator op="subtraction" type="int">
<lhs>
<literal type="int" value="331"/>
</lhs>
<rhs>
<literal type="int" value="505"/>
</rhs>
</operator>
</rhs>
</unary>
</rhs>
</brackets>
</stream>
<return type="int">
<operator op="addition" type="int">
<lhs>
<brackets type="int">
<rhs>
<operator op="addition" type="int">
<lhs>
<brackets type="int">
<rhs>
<brackets type="int">
<rhs>
<literal type="int" value="-739"/>
</rhs>
</brackets>
</rhs>
</brackets>
</lhs>
<rhs>
<operator op="addition" type="int">
<lhs>
<operator op="subtraction" type="int">
<lhs>
<literal type="int" value="-845"/>
</lhs>
<rhs>
<literal type="int" value="905"/>
</rhs>
</operator>
</lhs>
<rhs>
<unary op="noop" type="int">
<rhs>
<literal type="int" value="399"/>
</rhs>
</unary>
</rhs>
</operator>
</rhs>
</operator>
</rhs>
</brackets>
</lhs>
<rhs>
<operator op="addition" type="int">
<lhs>
<operator op="addition" type="int">
<lhs>
<brackets type="int">
<rhs>
<operator op="subtraction" type="int">
<lhs>
<literal type="int" value="-571"/>
</lhs>
<rhs>
<literal type="int" value="282"/>
</rhs>
</operator>
</rhs>
</brackets>
</lhs>
<rhs>
<operator op="subtraction" type="int">
<lhs>
<unary op="noop" type="int">
<rhs>
<literal type="int" value="61"/>
</rhs>
</unary>
</lhs>
<rhs>
<operator op="addition" type="int">
<lhs>
<literal type="int" value="-631"/>
</lhs>
<rhs>
<literal type="int" value="726"/>
</rhs>
</operator>
</rhs>
</operator>
</rhs>
</operator>
</lhs>
<rhs>
<brackets type="int">
<rhs>
<unary op="noop" type="int">
<rhs>
<brackets type="int">
<rhs>
<literal type="int" value="-685"/>
</rhs>
</brackets>
</rhs>
</unary>
</rhs>
</brackets>
</rhs>
</operator>
</rhs>
</operator>
</return>
<declaration type="int">
<variable name="Pokan" type="int" mut="var"/>
<rhs>
<operator op="addition" type="int">
<lhs>
<operator op="subtraction" type="int">
<lhs>
<operator op="addition" type="int">
<lhs>
<brackets type="int">
<rhs>
<operator op="addition" type="int">
<lhs>
<literal type="int" value="-841"/>
</lhs>
<rhs>
<literal type="int" value="364"/>
</rhs>
</operator>
</rhs>
</brackets>
</lhs>
<rhs>
<operator op="division" type="int">
<lhs>
<brackets type="int">
<rhs>
<literal type="int" value="753"/>
</rhs>
</brackets>
</lhs>
<rhs>
<brackets type="int">
<rhs>
<literal type="int" value="-57"/>
</rhs>
</brackets>
</rhs>
</operator>
</rhs>
</operator>
</lhs>
<rhs>
<literal type="int" value="-321"/>
</rhs>
</operator>
</lhs>
<rhs>
<operator op="addition" type="int">
<lhs>
<unary op="noop" type="int">
<rhs>
<literal type="int" value="17"/>
</rhs>
</unary>
</lhs>
<rhs>
<literal type="int" value="782"/>
</rhs>
</operator>
</rhs>
</operator>
</rhs>
</declaration>
<stream type="std_output">
<unary op="noop" type="int">
<rhs>
<brackets type="int">
<rhs>
<operator op="subtraction" type="int">
<lhs>
<operator op="addition" type="int">
<lhs>
<brackets type="int">
<rhs>
<literal type="int" value="645"/>
</rhs>
</brackets>
</lhs>
<rhs>
<literal type="int" value="543"/>
</rhs>
</operator>
</lhs>
<rhs>
<operator op="addition" type="int">
<lhs>
<operator op="subtraction" type="int">
<lhs>
<literal type="int" value="51"/>
</lhs>
<rhs>
<literal type="int" value="-779"/>
</rhs>
</operator>
</lhs>
<rhs>
<literal type="int" value="553"/>
</rhs>
</operator>
</rhs>
</operator>
</rhs>
</brackets>
</rhs>
</unary>
</stream>
<declaration type="int">
<variable name="byway" type="int" mut="var"/>
<rhs>
<operator op="addition" type="int">
<lhs>
<operator op="division" type="int">
<lhs>
<literal type="int" value="959"/>
</lhs>
<rhs>
<literal type="int" value="-320"/>
</rhs>
</operator>
</lhs>
<rhs>
<operator op="addition" type="int">
<lhs>
<brackets type="int">
<rhs>
<brackets type="int">
<rhs>
<operator op="addition" type="int">
<lhs>
<literal type="int" value="467"/>
</lhs>
<rhs>
<literal type="int" value="-160"/>
</rhs>
</operator>
</rhs>
</brackets>
</rhs>
</brackets>
</lhs>
<rhs>
<operator op="addition" type="int">
<lhs>
<literal type="int" value="-137"/>
</lhs>
<rhs>
<operator op="subtraction" type="int">
<lhs>
<brackets type="int">
<rhs>
<literal type="int" value="-23"/>
</rhs>
</brackets>
</lhs>
<rhs>
<unary op="noop" type="int">
<rhs>
<literal type="int" value="371"/>
</rhs>
</unary>
</rhs>
</operator>
</rhs>
</operator>
</rhs>
</operator>
</rhs>
</operator>
</rhs>
</declaration>
<assignment>
<variable name="Pokan" type="int" mut="var"/>
<rhs>
<literal type="int" value="734"/>
</rhs>
</assignment>
</block>
</procedure>
</block>