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

Avoid out of bounds when calculating b.URI[startPos:] #69

Merged
merged 2 commits into from
Jul 18, 2023
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
4 changes: 4 additions & 0 deletions gltf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gltf

import (
"encoding/base64"
"errors"
"strings"
"sync"
)
Expand Down Expand Up @@ -133,6 +134,9 @@ func (b *Buffer) marshalData() ([]byte, error) {
return nil, nil
}
startPos := len(mimetypeApplicationOctet) + 1
if len(b.URI) < startPos {
return nil, errors.New("gltf: Invalid base64 content")
}
sl, err := base64.StdEncoding.DecodeString(b.URI[startPos:])
if len(sl) == 0 || err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions gltf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func TestBuffer_marshalData(t *testing.T) {
{"empty", &Buffer{URI: "data:application/octet-stream;base64,"}, nil, false},
{"test", &Buffer{URI: "data:application/octet-stream;base64,TEST"}, []byte{76, 68, 147}, false},
{"complex", &Buffer{URI: "data:application/octet-stream;base64,YW55IGNhcm5hbCBwbGVhcw=="}, []byte{97, 110, 121, 32, 99, 97, 114, 110, 97, 108, 32, 112, 108, 101, 97, 115}, false},
{"invalid", &Buffer{URI: "data:application/octet-stream;base64"}, nil, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading