Skip to content

Commit

Permalink
container: Prevent potential panic of version getter
Browse files Browse the repository at this point in the history
Previously, `Container.Version` method threw panic when being called on
any instance which had not been protocol-decoded. While this was not a
big problem because this field does not bring any practical benefit, in
general it could generate unsafe code. For example, when the caller does
not know how exactly the accepted instance is created.

Now method returns zero version if underlying protocol field is unset.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Sep 30, 2024
1 parent 6bd2b6f commit 3173cad
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ func (x Container) AssertID(id cid.ID) bool {
// Version returns the NeoFS API version this container was created with.
func (x Container) Version() version.Version {
var v version.Version
_ = v.ReadFromV2(*x.v2.GetVersion()) // No, this can't fail for x.
if m := x.v2.GetVersion(); m != nil {
_ = v.ReadFromV2(*m)
}
return v
}

0 comments on commit 3173cad

Please sign in to comment.