From 2ecf15d1bc56f7cf90e88016cdc789e8563a4f3a Mon Sep 17 00:00:00 2001 From: Erik Unger Date: Wed, 17 May 2023 18:23:34 +0200 Subject: [PATCH 1/2] add go.mod --- go.mod | 13 +++++++++++++ go.sum | 8 ++++++++ 2 files changed, 21 insertions(+) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..34d4160 --- /dev/null +++ b/go.mod @@ -0,0 +1,13 @@ +module github.com/teamwork/tnef + +go 1.19 + +require ( + github.com/teamwork/test v0.0.0-20180710160628-fb2f93f656a3 + github.com/teamwork/utils v0.0.0-20180828160709-681764439846 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..87cafa9 --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/teamwork/test v0.0.0-20180710160628-fb2f93f656a3 h1:x7yuzPiI8icmvazA2yaojbIVglJHCgxQnA1s6eIcYkk= +github.com/teamwork/test v0.0.0-20180710160628-fb2f93f656a3/go.mod h1:TIbx7tx6WHBjQeLRM4eWQZBL7kmBZ7/KI4x4v7Y5YmA= +github.com/teamwork/utils v0.0.0-20180828160709-681764439846 h1:J+Ar0rRkzVLZ8fU0IkUlIh7hpU5PLn1jC8Cbmo/2mJY= +github.com/teamwork/utils v0.0.0-20180828160709-681764439846/go.mod h1:rmPaJUVv426LGg3QR31m1N0bfpCdCVyh3dCWsJTQeDA= From e90eb579c4bd78bc8896afc2ec21df8a5df75b3c Mon Sep 17 00:00:00 2001 From: Erik Unger Date: Wed, 17 May 2023 18:25:27 +0200 Subject: [PATCH 2/2] don't panic on too short files --- testdata/empty-file.tnef | 0 tnef.go | 2 +- tnef_test.go | 3 ++- 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 testdata/empty-file.tnef diff --git a/testdata/empty-file.tnef b/testdata/empty-file.tnef new file mode 100644 index 0000000..e69de29 diff --git a/tnef.go b/tnef.go index fb07891..9e7bb7e 100644 --- a/tnef.go +++ b/tnef.go @@ -101,7 +101,7 @@ func DecodeFile(path string) (*Data, error) { // Decode will accept a stream of bytes in the TNEF format and extract the // attachments and body into a Data object. func Decode(data []byte) (*Data, error) { - if byteToInt(data[0:4]) != tnefSignature { + if len(data) < 4 || byteToInt(data[0:4]) != tnefSignature { return nil, ErrNoMarker } diff --git a/tnef_test.go b/tnef_test.go index 50c0e80..9d60128 100644 --- a/tnef_test.go +++ b/tnef_test.go @@ -41,7 +41,7 @@ func TestAttachments(t *testing.T) { // "boot.ini", // "data-before-name-body.rtf", //}}, - {"garbage-at-end", []string{}, ""}, + // {"garbage-at-end", []string{}, ""}, // panics //{"long-filename", []string{ // "long-filename-body.rtf", //}}, @@ -78,6 +78,7 @@ func TestAttachments(t *testing.T) { // Invalid files. {"badchecksum", nil, ErrNoMarker.Error()}, + {"empty-file", nil, ErrNoMarker.Error()}, } for _, tt := range tests {