@@ -521,7 +521,9 @@ module DynamoToStruct {
521
521
// See "The Parent Trick" for details: <https://leino.science/papers/krml283.html>.
522
522
function method MapAttrToBytes (ghost parent: AttributeValue , m: MapAttributeValue , depth : nat ): (ret: Result< seq < uint8> , string > )
523
523
requires forall kv < - m. Items :: kv. 1 < parent
524
+ ensures MAX_MAP_SIZE < |m| ==> ret. Failure?
524
525
{
526
+ :- Need (|m| <= MAX_MAP_SIZE, "Map exceeds limit of " + MAX_MAP_SIZE_STR + " entries.");
525
527
// = specification/dynamodb-encryption-client/ddb-attribute-serialization.md#value-type
526
528
// # Value Type MUST be the [Type ID](#type-id) of the type of [Map Value](#map-value).
527
529
@@ -543,7 +545,9 @@ module DynamoToStruct {
543
545
}
544
546
545
547
function method ListAttrToBytes (l: ListAttributeValue , depth : nat ): (ret: Result< seq < uint8> , string > )
548
+ ensures MAX_LIST_LENGTH < |l| ==> ret. Failure?
546
549
{
550
+ :- Need (|l| <= MAX_LIST_LENGTH, "List exceeds limit of " + MAX_LIST_LENGTH_STR + " entries.");
547
551
var count :- U32ToBigEndian (|l|);
548
552
var body :- CollectList (l, depth);
549
553
Success (count + body)
@@ -890,6 +894,7 @@ module DynamoToStruct {
890
894
resultList : AttrValueAndLength )
891
895
: (ret : Result< AttrValueAndLength, string > )
892
896
requires resultList. val. L?
897
+ requires remainingCount <= MAX_LIST_LENGTH
893
898
ensures ret. Success? ==> ret. value. val. L?
894
899
requires |serialized| + resultList. len == origSerializedSize
895
900
ensures ret. Success? ==> ret. value. len <= origSerializedSize
@@ -922,6 +927,7 @@ module DynamoToStruct {
922
927
resultMap : AttrValueAndLength )
923
928
: (ret : Result< AttrValueAndLength, string > )
924
929
requires resultMap. val. M?
930
+ requires remainingCount <= MAX_MAP_SIZE
925
931
ensures ret. Success? ==> ret. value. val. M?
926
932
requires |serialized| + resultMap. len == origSerializedSize
927
933
ensures ret. Success? ==> ret. value. len <= origSerializedSize
@@ -1056,6 +1062,7 @@ module DynamoToStruct {
1056
1062
Failure ("List Structured Data has less than 4 bytes")
1057
1063
else
1058
1064
var len :- BigEndianToU32 (value);
1065
+ :- Need (len <= MAX_MAP_SIZE, "Map exceeds limit of " + MAX_MAP_SIZE_STR + " entries.");
1059
1066
var value := value[LENGTH_LEN.. ];
1060
1067
DeserializeMap (value, len, |value| + LENGTH_LEN + lengthBytes, depth, AttrValueAndLength(AttributeValue.M(map[]), LENGTH_LEN + lengthBytes))
1061
1068
@@ -1064,6 +1071,7 @@ module DynamoToStruct {
1064
1071
Failure ("List Structured Data has less than 4 bytes")
1065
1072
else
1066
1073
var len :- BigEndianToU32 (value);
1074
+ :- Need (len <= MAX_LIST_LENGTH, "List exceeds limit of " + MAX_LIST_LENGTH_STR + " entries.");
1067
1075
var value := value[LENGTH_LEN.. ];
1068
1076
DeserializeList (value, len, |value| + LENGTH_LEN + lengthBytes, depth, AttrValueAndLength(AttributeValue.L([]), LENGTH_LEN + lengthBytes))
1069
1077
0 commit comments