Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several panics in ParseCalendar #85

Merged
merged 4 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions calendar_fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build go1.18
// +build go1.18

package ics

import (
"bytes"
"os"
"testing"

"github.com/stretchr/testify/require"
)

func FuzzParseCalendar(f *testing.F) {
ics, err := os.ReadFile("testdata/timeparsing.ics")
require.NoError(f, err)
f.Add(ics)
f.Fuzz(func(t *testing.T, ics []byte) {
_, err := ParseCalendar(bytes.NewReader(ics))
t.Log(err)
})
}
10 changes: 10 additions & 0 deletions property.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ics

import (
"bytes"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -194,6 +195,9 @@ func parsePropertyParam(r *BaseProperty, contentLine string, p int) (*BaseProper
k, v := "", ""
k = string(contentLine[p : p+tokenPos[1]])
p += tokenPos[1]
if p >= len(contentLine) {
return nil, p, fmt.Errorf("missing property param operator for %s in %s", k, r.IANAToken)
}
switch rune(contentLine[p]) {
case '=':
p += 1
Expand All @@ -210,6 +214,9 @@ func parsePropertyParam(r *BaseProperty, contentLine string, p int) (*BaseProper
return nil, 0, fmt.Errorf("parse error: %w %s in %s", err, k, r.IANAToken)
}
r.ICalParameters[k] = append(r.ICalParameters[k], v)
if p >= len(contentLine) {
return nil, p, fmt.Errorf("unexpected end of property %s", r.IANAToken)
}
switch rune(contentLine[p]) {
case ',':
p += 1
Expand Down Expand Up @@ -258,6 +265,9 @@ func parsePropertyParamValue(s string, p int) (string, int, error) {
0x1C, 0x1D, 0x1E, 0x1F:
return "", 0, fmt.Errorf("unexpected char ascii:%d in property param value", s[p])
case '\\':
if p+2 >= len(s) {
return "", 0, errors.New("unexpected end of param value")
}
r = append(r, []byte(FromText(string(s[p+1:p+2])))...)
p++
continue
Expand Down
2 changes: 2 additions & 0 deletions testdata/fuzz/FuzzParseCalendar/5940bf4f62ecac30
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("0;0=\\")
2 changes: 2 additions & 0 deletions testdata/fuzz/FuzzParseCalendar/5f69bd55acfce1af
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("0;0")
2 changes: 2 additions & 0 deletions testdata/fuzz/FuzzParseCalendar/8856e23652c60ed6
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("0;0=0")
Loading