Skip to content

Commit 1e91f10

Browse files
committed
return an error when unmarshaling binary AV into a smaller array
fixes #124
1 parent 10b9f1a commit 1e91f10

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

decode.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ func unmarshalReflect(av *dynamodb.AttributeValue, rv reflect.Value) error {
202202
case av.BS != nil:
203203
for _, bb := range av.BS {
204204
kv := reflect.New(rv.Type().Key()).Elem()
205-
for i, b := range bb {
206-
kv.Index(i).Set(reflect.ValueOf(b))
207-
}
205+
reflect.Copy(kv, reflect.ValueOf(bb))
208206
rv.SetMapIndex(kv, truthy)
209207
}
210208
return nil
@@ -217,9 +215,10 @@ func unmarshalReflect(av *dynamodb.AttributeValue, rv reflect.Value) error {
217215
elemtype := arr.Type().Elem()
218216
switch {
219217
case av.B != nil:
220-
for i, b := range av.B {
221-
arr.Index(i).Set(reflect.ValueOf(b))
218+
if len(av.B) > arr.Len() {
219+
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))
222220
}
221+
reflect.Copy(arr, reflect.ValueOf(av.B))
223222
rv.Set(arr)
224223
return nil
225224
case av.L != nil:

0 commit comments

Comments
 (0)