kopia lustrzana https://github.com/collective/icalendar
Merge branch 'feat/oss-fuzz-integration'
commit
484f9930d6
|
@ -358,6 +358,10 @@ class Component(CaselessDict):
|
||||||
elif uname == 'END':
|
elif uname == 'END':
|
||||||
# we are done adding properties to this component
|
# we are done adding properties to this component
|
||||||
# so pop it from the stack and add it to the new top.
|
# so pop it from the stack and add it to the new top.
|
||||||
|
if not stack:
|
||||||
|
# The stack is currently empty, the input must be invalid
|
||||||
|
raise ValueError('END encountered without an accompanying BEGIN!')
|
||||||
|
|
||||||
component = stack.pop()
|
component = stack.pop()
|
||||||
if not stack: # we are at the end
|
if not stack: # we are at the end
|
||||||
comps.append(component)
|
comps.append(component)
|
||||||
|
|
|
@ -17,16 +17,24 @@
|
||||||
import atheris
|
import atheris
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
with atheris.instrument_imports(include=['icalendar']):
|
with atheris.instrument_imports(
|
||||||
from icalendar import Calendar
|
include=['icalendar'],
|
||||||
|
exclude=['pytz', 'six', 'site_packages', 'pkg_resources', 'dateutil']):
|
||||||
|
import icalendar
|
||||||
|
|
||||||
|
_value_error_matches = [
|
||||||
|
"component", "parse", "Expected", "Wrong date format", "END encountered",
|
||||||
|
"vDDD", 'recurrence', 'Wrong datetime', 'Offset must', 'Invalid iCalendar'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@atheris.instrument_func
|
||||||
def TestOneInput(data):
|
def TestOneInput(data):
|
||||||
fdp = atheris.FuzzedDataProvider(data)
|
fdp = atheris.FuzzedDataProvider(data)
|
||||||
try:
|
try:
|
||||||
b = fdp.ConsumeBool()
|
b = fdp.ConsumeBool()
|
||||||
|
|
||||||
cal = Calendar.from_ical(fdp.ConsumeString(fdp.remaining_bytes()))
|
cal = icalendar.Calendar.from_ical(fdp.ConsumeString(fdp.remaining_bytes()))
|
||||||
|
|
||||||
if b:
|
if b:
|
||||||
for event in cal.walk('VEVENT'):
|
for event in cal.walk('VEVENT'):
|
||||||
|
@ -34,10 +42,11 @@ def TestOneInput(data):
|
||||||
else:
|
else:
|
||||||
cal.to_ical()
|
cal.to_ical()
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
if "component" in str(e) or "parse" in str(e) or "Expected" in str(e):
|
if any(m in str(e) for m in _value_error_matches):
|
||||||
return -1
|
return -1
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
atheris.Setup(sys.argv, TestOneInput)
|
atheris.Setup(sys.argv, TestOneInput)
|
||||||
atheris.Fuzz()
|
atheris.Fuzz()
|
||||||
|
|
|
@ -250,8 +250,19 @@ class vDDDLists:
|
||||||
self.dts = vDDD
|
self.dts = vDDD
|
||||||
|
|
||||||
def to_ical(self):
|
def to_ical(self):
|
||||||
dts_ical = (dt.to_ical() for dt in self.dts)
|
dts_ical = [dt.to_ical() for dt in self.dts]
|
||||||
return b",".join(dts_ical)
|
|
||||||
|
# Make sure all elements are of the same type
|
||||||
|
if dts_ical and all(type(dt) is type(dts_ical[0]) for dt in dts_ical):
|
||||||
|
first_dt = dts_ical[0]
|
||||||
|
if isinstance(first_dt, bytes):
|
||||||
|
return b",".join(dts_ical)
|
||||||
|
elif isinstance(first_dt, str):
|
||||||
|
return ",".join(dts_ical)
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Unexpected type {type(first_dt)} in vDDD list!")
|
||||||
|
else:
|
||||||
|
raise ValueError("Type mismatch in vDDD list!")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_ical(ical, timezone=None):
|
def from_ical(ical, timezone=None):
|
||||||
|
|
Ładowanie…
Reference in New Issue