Skip to content

Commit

Permalink
return an error when unmarshaling binary AV into a smaller array
Browse files Browse the repository at this point in the history
fixes #124
  • Loading branch information
guregu committed May 1, 2020
1 parent 10b9f1a commit 1e91f10
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@ func unmarshalReflect(av *dynamodb.AttributeValue, rv reflect.Value) error {
case av.BS != nil:
for _, bb := range av.BS {
kv := reflect.New(rv.Type().Key()).Elem()
for i, b := range bb {
kv.Index(i).Set(reflect.ValueOf(b))
}
reflect.Copy(kv, reflect.ValueOf(bb))
rv.SetMapIndex(kv, truthy)
}
return nil
Expand All @@ -217,9 +215,10 @@ func unmarshalReflect(av *dynamodb.AttributeValue, rv reflect.Value) error {
elemtype := arr.Type().Elem()
switch {
case av.B != nil:
for i, b := range av.B {
arr.Index(i).Set(reflect.ValueOf(b))
if len(av.B) > arr.Len() {
return fmt.Errorf("dynamo: cannot marshal %s into %s; too small (dst len: %d, src len: %d)", avTypeName(av), arr.Type().String(), arr.Len(), len(av.B))
}
reflect.Copy(arr, reflect.ValueOf(av.B))
rv.Set(arr)
return nil
case av.L != nil:
Expand Down

0 comments on commit 1e91f10

Please sign in to comment.