[openpyxl]: fix exception control for internal error (#8616)

Fix exception handling for issues.
48488 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=48488)
48506 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=48506)y
This commit is contained in:
Arthur Chan 2022-09-28 14:42:57 +01:00 committed by GitHub
parent f46748f307
commit 48ef7e5a0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 10 deletions

View File

@ -24,20 +24,29 @@ def TestInput(data):
wb = Workbook()
ws = wb.active
#Set Comment
c1 = ws['A1'].comment
c1 = Comment(fdp.ConsumeString(10),fdp.ConsumeString(10))
c1 = Comment(fdp.ConsumeUnicodeNoSurrogates(10),
fdp.ConsumeUnicodeNoSurrogates(10))
c1.width = 300
c1.height = 50
ws['A1'].comment = c1
#Double assign comment
c2 = Comment(fdp.ConsumeString(10),fdp.ConsumeString(10))
c2 = Comment(fdp.ConsumeUnicodeNoSurrogates(10),
fdp.ConsumeUnicodeNoSurrogates(10))
ws['B1'].comment = c2
ws['C1'].comment = c2
wb.save('%s.xlsx'%fdp.ConsumeString(10))
try:
wb.save('%s.xlsx'%fdp.ConsumeUnicodeNoSurrogates(10))
except ValueError as e:
if "embedded null byte" not in str(e):
raise e
except FileNotFoundError:
# Expected for corrupted file name
pass
def main():
atheris.Setup(sys.argv, TestInput, enable_python_coverage=True)

View File

@ -17,17 +17,24 @@
import atheris
import sys
with atheris.instrument_imports():
from openpyxl.formula import Tokenizer
from openpyxl.formula.translate import Translator
from openpyxl.formula.tokenizer import *
from openpyxl.formula.translate import *
def TestInput(data):
fdp = atheris.FuzzedDataProvider(data)
#Initial tokenizer for random string and process it
Tokenizer(fdp.ConsumeString(200))
try:
#Initial tokenizer for random string and process it
Tokenizer(fdp.ConsumeString(200))
#Translate random string formulae
Translator(fdp.ConsumeString(200), origin="A1").translate_formula("B2")
#Translate random string formulae
Translator(fdp.ConsumeString(200), origin="A1").translate_formula("B2")
except IndexError as e:
if 'empty list' not in str(e):
raise e
except (TokenizerError, TranslatorError):
# Internal error handling is expected
pass
def main():
atheris.Setup(sys.argv, TestInput, enable_python_coverage=True)