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

Don't panic on short/empty data #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Empty file added testdata/empty-file.tnef
Empty file.
2 changes: 1 addition & 1 deletion tnef.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion tnef_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
//}},
Expand Down Expand Up @@ -78,6 +78,7 @@ func TestAttachments(t *testing.T) {

// Invalid files.
{"badchecksum", nil, ErrNoMarker.Error()},
{"empty-file", nil, ErrNoMarker.Error()},
}

for _, tt := range tests {
Expand Down