Skip to content

Commit 01e6018

Browse files
authored
Merge pull request #10 from Patch2PDF/null-ptr-dereference
Fix: Null ptr dereference
2 parents 257e7e9 + bbfeb2e commit 01e6018

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

gdtf-parser.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ func ParseGDTFZipReader(zipfile *zip.Reader, readMeshes bool, readThumbnail bool
3333
fileMap[file.Name] = file
3434
}
3535

36+
if fileMap["description.xml"] == nil {
37+
return nil, fmt.Errorf("Invalid GDTF: missing description.xml")
38+
}
3639
xmlFile, err := fileMap["description.xml"].Open()
3740
if err != nil {
3841
return nil, err

internal/types/gdtfxml/general.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ type ConvertToDestinationMapStruct[T any] interface {
245245
}
246246

247247
func ParseList[Source ConvertToDestinationStruct[Destination], Destination any](source *[]Source) []*Destination {
248+
if source == nil {
249+
return []*Destination{}
250+
}
248251
var destination []*Destination = make([]*Destination, len(*source))
249252
for index, element := range *source {
250253
parsedElement := element.Parse()
@@ -254,6 +257,9 @@ func ParseList[Source ConvertToDestinationStruct[Destination], Destination any](
254257
}
255258

256259
func ParseMap[Source ConvertToDestinationMapStruct[Destination], Destination any](source *[]Source) map[string]*Destination {
260+
if source == nil {
261+
return map[string]*Destination{}
262+
}
257263
destination := make(map[string]*Destination)
258264
for _, element := range *source {
259265
parsedElement := element.Parse()

0 commit comments

Comments
 (0)