From 24e2e1ce84e0b30fd8858dc5324ef5368c79e854 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 9 Dec 2022 14:39:46 +0100 Subject: [PATCH] Fix infinite loop in kolab_storage_dataset --- plugins/calendar/calendar.php | 3 ++- .../calendar/drivers/caldav/caldav_calendar.php | 4 ++++ .../lib/libcalendaring_vcalendar.php | 16 +++++++++------- plugins/libkolab/lib/kolab_storage_dataset.php | 5 +++-- .../libkolab/lib/kolab_storage_dav_folder.php | 6 +++++- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php index ba2f21e4..7c4c44d7 100644 --- a/plugins/calendar/calendar.php +++ b/plugins/calendar/calendar.php @@ -2305,7 +2305,8 @@ $("#rcmfd_new_category").keypress(function(event) { private function is_html($event) { // check for opening and closing or tags - return preg_match('/<(html|body)(\s+[a-z]|>)/', $event['description'], $m) + return !empty($event['description']) + && preg_match('/<(html|body)(\s+[a-z]|>)/', $event['description'], $m) && strpos($event['description'], '') > 0; } diff --git a/plugins/calendar/drivers/caldav/caldav_calendar.php b/plugins/calendar/drivers/caldav/caldav_calendar.php index 7d4e94f7..15608261 100644 --- a/plugins/calendar/drivers/caldav/caldav_calendar.php +++ b/plugins/calendar/drivers/caldav/caldav_calendar.php @@ -265,6 +265,10 @@ class caldav_calendar extends kolab_storage_dav_folder } foreach ($this->storage->select($query) as $record) { + if (empty($record)) { + continue; + } + $event = $this->_to_driver_event($record, !$virtual, false); // remember seen categories diff --git a/plugins/libcalendaring/lib/libcalendaring_vcalendar.php b/plugins/libcalendaring/lib/libcalendaring_vcalendar.php index f3cdd063..733f008a 100644 --- a/plugins/libcalendaring/lib/libcalendaring_vcalendar.php +++ b/plugins/libcalendaring/lib/libcalendaring_vcalendar.php @@ -129,9 +129,10 @@ class libcalendaring_vcalendar implements Iterator /** * Import events from iCalendar format * - * @param string vCalendar input - * @param string Input charset (from envelope) - * @param boolean True if parsing exceptions should be forwarded to the caller + * @param string vCalendar input + * @param string Input charset (from envelope) + * @param bool True if parsing exceptions should be forwarded to the caller + * * @return array List of events extracted from the input */ public function import($vcal, $charset = 'UTF-8', $forward_exceptions = false, $memcheck = true) @@ -166,15 +167,16 @@ class libcalendaring_vcalendar implements Iterator } } - return array(); + return []; } /** * Read iCalendar events from a file * - * @param string File path to read from - * @param string Input charset (from envelope) - * @param boolean True if parsing exceptions should be forwarded to the caller + * @param string File path to read from + * @param string Input charset (from envelope) + * @param bool True if parsing exceptions should be forwarded to the caller + * * @return array List of events extracted from the file */ public function import_from_file($filepath, $charset = 'UTF-8', $forward_exceptions = false) diff --git a/plugins/libkolab/lib/kolab_storage_dataset.php b/plugins/libkolab/lib/kolab_storage_dataset.php index 5953805b..fb81eab1 100644 --- a/plugins/libkolab/lib/kolab_storage_dataset.php +++ b/plugins/libkolab/lib/kolab_storage_dataset.php @@ -132,10 +132,11 @@ class kolab_storage_dataset implements Iterator, ArrayAccess, Countable while (isset($this->index[$idx]) && count($uids) < self::CHUNK_SIZE) { if (isset($this->data[$idx]) && !is_string($this->data[$idx])) { // skip objects that had the raw content in the cache (are not empty) - continue; + } + else { + $uids[$idx] = $this->index[$idx]; } - $uids[$idx] = $this->index[$idx]; $idx++; } diff --git a/plugins/libkolab/lib/kolab_storage_dav_folder.php b/plugins/libkolab/lib/kolab_storage_dav_folder.php index c1141144..a524ef41 100644 --- a/plugins/libkolab/lib/kolab_storage_dav_folder.php +++ b/plugins/libkolab/lib/kolab_storage_dav_folder.php @@ -514,10 +514,14 @@ class kolab_storage_dav_folder extends kolab_storage_folder * * @param array Object data in kolab_dav_client::fetchData() format * - * @return array Object properties + * @return array|false Object properties, False on error */ public function from_dav($object) { + if (empty($object ) || empty($object['data'])) { + return false; + } + if ($this->type == 'event') { $ical = libcalendaring::get_ical(); $events = $ical->import($object['data']);