Skip to content

Commit

Permalink
improve the error handling when decoding table rows with variant types (
Browse files Browse the repository at this point in the history
#214)

* add bound check for variant types

* handle alias, improve error message

* add changelog
  • Loading branch information
fschoell authored Nov 9, 2023
1 parent 5d4ee54 commit 59afdfa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

#### Fixed

* Improved the error handling when decoding table rows with variant types.

* Fixed decoding of table rows with variant types.

* Fixed serialization of `map[K]V` when using `eos.MarshalBinary` so that ordering in which the keys are serialized is in lexicographical order, just like JSON serialization.
Expand Down
8 changes: 5 additions & 3 deletions abidecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ func (a *ABI) decode(binaryDecoder *Decoder, structName string) (map[string]inte
}

if variant := a.VariantForName(structName); variant != nil {
out, err := binaryDecoder.ReadUvarint32()
variantIndex, err := binaryDecoder.ReadUvarint32()
if err != nil {
zlog.Error("error reading variant", zap.Error(err))
return nil, fmt.Errorf("error reading variant: %w", err)
} else if int(variantIndex) >= len(variant.Types) {
return nil, fmt.Errorf("variant type index is unknown, got type index %d, know up to index %d", variantIndex, len(variant.Types)-1)
}
structName = variant.Types[out]
structName, _ = a.TypeNameForNewTypeName(variant.Types[variantIndex])
}

structure := a.StructForName(structName)
Expand Down

0 comments on commit 59afdfa

Please sign in to comment.