Skip to content

Commit f894395

Browse files
authored
Merge pull request #69 from pic4xiu/master
Avoid out of bounds when calculating b.URI[startPos:]
2 parents 7ed65a3 + bbe10e4 commit f894395

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

gltf.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gltf
22

33
import (
44
"encoding/base64"
5+
"errors"
56
"strings"
67
"sync"
78
)
@@ -133,6 +134,9 @@ func (b *Buffer) marshalData() ([]byte, error) {
133134
return nil, nil
134135
}
135136
startPos := len(mimetypeApplicationOctet) + 1
137+
if len(b.URI) < startPos {
138+
return nil, errors.New("gltf: Invalid base64 content")
139+
}
136140
sl, err := base64.StdEncoding.DecodeString(b.URI[startPos:])
137141
if len(sl) == 0 || err != nil {
138142
return nil, err

gltf_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func TestBuffer_marshalData(t *testing.T) {
9696
{"empty", &Buffer{URI: "data:application/octet-stream;base64,"}, nil, false},
9797
{"test", &Buffer{URI: "data:application/octet-stream;base64,TEST"}, []byte{76, 68, 147}, false},
9898
{"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},
99+
{"invalid", &Buffer{URI: "data:application/octet-stream;base64"}, nil, true},
99100
}
100101
for _, tt := range tests {
101102
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)