Skip to content

Commit

Permalink
Return an error when getting header attributes for invalid header ver…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
andriygm authored and jmwoliver committed Jan 24, 2025
1 parent de77841 commit 6882c03
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions internal/distributions/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,13 @@ type BaseDistribution struct {
Dynamic []string `json:"dynamic"`
}

func (bd *BaseDistribution) GetHeaderAttrs() []HeaderAttr {
func (bd *BaseDistribution) GetHeaderAttrs() ([]HeaderAttr, error) {
ha, exists := HeaderAttrs[bd.MetadataVersion]
if exists {
return ha
if !exists {
return []HeaderAttr{}, fmt.Errorf("header attributes for metadata version %s not found", bd.MetadataVersion)
}
return []HeaderAttr{}

return ha, nil
}

func (bd *BaseDistribution) Parse(data []byte) error {
Expand All @@ -200,7 +201,12 @@ func (bd *BaseDistribution) Parse(data []byte) error {
bd.MetadataVersion = headerValue
}

for _, headerAttr := range bd.GetHeaderAttrs() {
headerAttrs, err := bd.GetHeaderAttrs()
if err != nil {
return err
}

for _, headerAttr := range headerAttrs {
if headerAttr.AttrName == "metadata_version" {
continue
}
Expand Down

0 comments on commit 6882c03

Please sign in to comment.