| 1 |
package plist |
| 2 |
|
| 3 |
import ( |
| 4 |
"strings" |
| 5 |
"testing" |
| 6 |
) |
| 7 |
|
| 8 |
var InvalidTextPlists = []struct { |
| 9 |
Name string |
| 10 |
Data string |
| 11 |
}{ |
| 12 |
{"Truncated array", "("}, |
| 13 |
{"Truncated dictionary", "{a=b;"}, |
| 14 |
{"Truncated dictionary 2", "{"}, |
| 15 |
{"Unclosed nested array", "{0=(/"}, |
| 16 |
{"Unclosed dictionary", "{0=/"}, |
| 17 |
{"Broken GNUStep data", "(<*I5>,<*I5>,<*I5>,<*I5>,*I16777215>,<*I268435455>,<*I4294967295>,<*I18446744073709551615>,)"}, |
| 18 |
{"Truncated nested array", "{0=(((/"}, |
| 19 |
{"Truncated dictionary with comment-like", "{/"}, |
| 20 |
{"Truncated array with comment-like", "(/"}, |
| 21 |
{"Truncated array with empty data", "(<>"}, |
| 22 |
{"Bad Extended Character", "{¬=A;}"}, |
| 23 |
{"Missing Equals in Dictionary", `{"A"A;}`}, |
| 24 |
{"Missing Semicolon in Dictionary", `{"A"=A}`}, |
| 25 |
{"Invalid GNUStep type", "<*F33>"}, |
| 26 |
{"Invalid GNUStep int", "(<*I>"}, |
| 27 |
{"Invalid GNUStep date", "<*D5>"}, |
| 28 |
{"Truncated GNUStep value", "<*I3"}, |
| 29 |
{"Invalid data", "<EQ>"}, |
| 30 |
{"Truncated unicode escape", `"\u231`}, |
| 31 |
{"Truncated hex escape", `"\x2`}, |
| 32 |
{"Truncated octal escape", `"\02`}, |
| 33 |
{"Truncated data", `<33`}, |
| 34 |
{"Uneven data", `<3>`}, |
| 35 |
{"Truncated block comment", `/* hello`}, |
| 36 |
{"Truncated quoted string", `"hi`}, |
| 37 |
{"Garbage after end of non-string", "<ab> cde"}, |
| 38 |
{"Broken UTF-16", "\xFE\xFF\x01"}, |
| 39 |
{"Truncated GNUStep data", "<"}, |
| 40 |
{"Truncated GNUStep base64 data (missing ])", `<[33==`}, |
| 41 |
{"Truncated GNUStep base64 data (missing >)", `<[33==]`}, |
| 42 |
{"Invalid GNUStep base64 data", `<[3]>`}, |
| 43 |
{"GNUStep extended value with EOF before type", "<*"}, |
| 44 |
{"GNUStep extended value terminated before type", "<*>"}, |
| 45 |
{"Empty GNUStep extended value", "<*I>"}, |
| 46 |
{"Unterminated GNUStep quoted value", "<*D\"5>"}, |
| 47 |
{"Unterminated GNUStep quoted value (EOF)", "<*D\""}, |
| 48 |
{"Poorly-terminated GNUStep quoted value", "<*D\">"}, |
| 49 |
{"Empty GNUStep quoted extended value", "<*D\"\">"}, |
| 50 |
} |
| 51 |
|
| 52 |
func TestInvalidTextPlists(t *testing.T) { |
| 53 |
for _, test := range InvalidTextPlists { |
| 54 |
subtest(t, test.Name, func(t *testing.T) { |
| 55 |
var obj interface{} |
| 56 |
buf := strings.NewReader(test.Data) |
| 57 |
err := NewDecoder(buf).Decode(&obj) |
| 58 |
if err == nil { |
| 59 |
t.Fatal("invalid plist failed to throw error") |
| 60 |
} else { |
| 61 |
t.Log(err) |
| 62 |
} |
| 63 |
}) |
| 64 |
} |
| 65 |
} |