skarim / vobject

A full-featured Python package for parsing and creating iCalendar and vCard files
https://vobject.sameenkarim.com
255 stars 93 forks source link

__tzidMap cache should not leak tzid into subsequent calendars #153

Open earlchew opened 5 years ago

earlchew commented 5 years ago

When vobject.readOne() or vobject.iCalendar() is used to read or create multiple calendars, the first time a timezone is encountered, its name is recorded in __tzidMap so that the timezone can later be discovered by name.

This is problematic because registerTzinfo() remembers the first instance, and not the most recent instance:

        tzid = obj.pickTzid(tzinfo)
        if tzid and not getTzid(tzid, False):
            registerTzid(tzid, tzinfo)
        return tzid

This means that in subsequent calendars contrary to its nameregisterTzinfo() does not register the instance, and a getTzid() actually retrieves the first instance that was encountered much earlier.

One scenario where this can be a problem is where calendar is ingested using readOne() containing some potentially arbitrary VTIMEZONE. After this a new calendar is created, and rather than using the definitive timezone information from pytz, instead uses the information read from the first calendar obtained via __tzidMap.