apognu / gocal

ICS file parser in Golang
MIT License
78 stars 24 forks source link

Panic when loading this ICS file #28

Closed StefanSchroeder closed 1 year ago

StefanSchroeder commented 1 year ago

Loading this ICS file

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//ZContent.net//Zap Calendar 1.0//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VEVENT
SUMMARY:Abraham Lincoln
UID:c7614cff-3549-4a00-9152-d25cc1fe077d
SEQUENCE:0
STATUS:CONFIRMED
TRANSP:TRANSPARENT
RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=2;BYMONTHDAY=12
DTSTART:20080212
DTEND:20080213
DTSTAMP:20150421T141403
CATEGORIES:U.S. Presidents,Civil War People
LOCATION:Hodgenville\, Kentucky
GEO:37.5739497;-85.7399606
DESCRIPTION:Born February 12\, 1809\nSixteenth President (1861-1865)\n\n\n
 \nhttp://AmericanHistoryCalendar.com
URL:http://americanhistorycalendar.com/peoplecalendar/1,328-abraham-lincol
 n
END:VEVENT
END:VCALENDAR

which was taken from https://icalendar.org/

and inserted in the sample program

package main

import (
  "github.com/apognu/gocal"
  "os"
  "time"
  "fmt"
)

func main() {
  f, _ := os.Open("my.ics")
  defer f.Close()

  start, end := time.Now(), time.Now().Add(12*30*24*time.Hour)

  c := gocal.NewParser(f)
  c.Start, c.End = &start, &end
  c.Parse()

  for _, e := range c.Events {
    fmt.Printf("%s on %s by %s", e.Summary, e.Start,
e.Organizer.Cn)
  }
}

yields

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x4e8124]

goroutine 1 [running]:
main.main()
    /home/bert/tmp/test/goics-test.go:24 +0x304
apognu commented 1 year ago

You are trying to access the Organizer property from an ICS file that does not have an ORGANIZER line, it is therefore nil, in your example.