@@ -980,10 +980,9 @@ func TestMalformedHamt(t *testing.T) {
980
980
bcat (b (0x40 + 1 ), b (kv .key )), // bytes(1) "\x??"
981
981
bcat (b (0x40 + 1 ), b (kv .value )))) // bytes(1) "\x??"
982
982
}
983
- return bcat (b (0xa0 + 1 ), // map(1)
984
- bcat (b (0x60 + 1 ), b (0x31 )), // string(1) "1"
985
- bcat (b (0x80 + byte (len (kvs ))), // array(?)
986
- en )) // bucket contents
983
+ return bcat (
984
+ b (0x80 + byte (len (kvs ))), // array(?)
985
+ en ) // bucket contents
987
986
}
988
987
989
988
// most minimal HAMT node with one k/v entry, sanity check we can load this
@@ -1040,65 +1039,25 @@ func TestMalformedHamt(t *testing.T) {
1040
1039
t .Fatal ("Should have returned ErrMalformedHamt for mismatch bitfield count" )
1041
1040
}
1042
1041
1043
- // test mixed link & bucket
1044
-
1045
- // this node contains 2 elements, the first is a plain entry with one bucket
1046
- // and with a single key of 0x0100, the second element is a link to a child
1047
- // node which happens to be the same CID as this node will be stored in.
1048
- // However, this second entry has both a CID and a bucket in the same
1049
- // element, which is not allowed. Without checks for exactly one of these
1050
- // two things then then a lookup for key 0x0100 would navigate through this
1051
- // node and back again as its own child to the first element.
1052
- store (
1053
- bcat (b (0x80 + 2 ), // array(2)
1054
- bcat (b (0x40 + 1 ), b (0x03 )), // bytes(1) "\x03" (bitmap)
1055
- bcat (b (0x80 + 2 ), // array(2)
1056
- bcat (b (0xa0 + 1 ), // map(1)
1057
- bcat (b (0x60 + 1 ), b (0x31 )), // string(1) "1"
1058
- bcat (b (0x80 + 1 ), // array(1)
1059
- bcat (b (0x80 + 2 ), // array(2)
1060
- bcat (b (0x40 + 2 ), []byte {0x01 , 0x00 }), // bytes(2) "\x0100"
1061
- bcat (b (0x40 + 1 ), b (0xff ))))), // bytes(1) "\xff"
1062
- bcat (b (0xa0 + 2 ), // map(2)
1063
- bcat (b (0x60 + 1 ), b (0x30 )), // string(1) "0"
1064
- bcat (b (0xd8 ), b (0x2a ), // tag(42)
1065
- b (0x58 ), b (0x27 ), // bytes(39)
1066
- cidBytes ), // cid
1067
- bcat (b (0x60 + 1 ), b (0x31 )), // string(1) "1"
1068
- bcat (b (0x80 + 1 ), // array(1)
1069
- bcat (b (0x80 + 2 ), // array(2)
1070
- bcat (b (0x40 + 1 ), b (0x01 )), // bytes(1) "\x00"
1071
- bcat (b (0x40 + 1 ), b (0xfe )))))))) // bytes(1) "\xff
1072
-
1073
- n , err = LoadNode (ctx , cs , bcid , UseTreeBitWidth (8 ), UseHashFunction (identityHash ))
1074
- if err == nil || n != nil || err .Error () != "Pointers should be a single element map" {
1075
- // no ErrMalformedHamt here possible bcause of cbor-gen wrapping
1076
- t .Fatal ("Should have returned error for bad Pointer cbor" )
1077
- }
1078
-
1079
1042
// test pointers with links have are DAG-CBOR multicodec
1080
1043
// sanity check minimal node pointing to a child node
1081
1044
store (
1082
1045
bcat (b (0x80 + 2 ), // array(2)
1083
1046
bcat (b (0x40 + 1 ), b (0x01 )), // bytes(1) "\x01" (bitmap)
1084
1047
bcat (b (0x80 + 1 ), // array(1)
1085
- bcat (b (0xa0 + 1 ), // map(1)
1086
- bcat (b (0x60 + 1 ), b (0x30 )), // string(1) "0"
1087
- bcat (b (0xd8 ), b (0x2a ), // tag(42)
1088
- b (0x58 ), b (0x27 ), // bytes(39)
1089
- cidBytes ))))) // cid
1048
+ bcat (b (0xd8 ), b (0x2a ), // tag(42)
1049
+ b (0x58 ), b (0x27 ), // bytes(39)
1050
+ cidBytes )))) // cid
1090
1051
load ()
1091
1052
1092
1053
// node pointing to a non-dag-cbor node
1093
1054
store (
1094
1055
bcat (b (0x80 + 2 ), // array(2)
1095
1056
bcat (b (0x40 + 1 ), b (0x01 )), // bytes(1) "\x01" (bitmap)
1096
1057
bcat (b (0x80 + 1 ), // array(1)
1097
- bcat (b (0xa0 + 1 ), // map(1)
1098
- bcat (b (0x60 + 1 ), b (0x30 )), // string(1) "0"
1099
- bcat (b (0xd8 ), b (0x2a ), // tag(42)
1100
- b (0x58 ), b (0x27 ), // bytes(39)
1101
- badCidBytes ))))) // cid
1058
+ bcat (b (0xd8 ), b (0x2a ), // tag(42)
1059
+ b (0x58 ), b (0x27 ), // bytes(39)
1060
+ badCidBytes )))) // cid
1102
1061
n , err = LoadNode (ctx , cs , bcid , UseTreeBitWidth (8 ), UseHashFunction (identityHash ))
1103
1062
if err != ErrMalformedHamt || n != nil {
1104
1063
t .Fatal ("Should have returned ErrMalformedHamt for bad child link codec" )
@@ -1178,11 +1137,9 @@ func TestMalformedHamt(t *testing.T) {
1178
1137
bcat (b (0x80 + 2 ), // array(2)
1179
1138
bcat (b (0x40 + 1 ), b (0x01 )), // bytes(1) "\x01" (bitmap)
1180
1139
bcat (b (0x80 + 1 ), // array(1)
1181
- bcat (b (0xa0 + 1 ), // map(1)
1182
- bcat (b (0x60 + 1 ), b (0x30 )), // string(1) "0"
1183
- bcat (b (0xd8 ), b (0x2a ), // tag(42)
1184
- b (0x58 ), b (0x27 ), // bytes(39)
1185
- ccidBytes ))))) // cid
1140
+ bcat (b (0xd8 ), b (0x2a ), // tag(42)
1141
+ b (0x58 ), b (0x27 ), // bytes(39)
1142
+ ccidBytes )))) // cid
1186
1143
1187
1144
vg , err := load ().FindRaw (ctx , string ([]byte {0x00 , 0x01 }))
1188
1145
// without validation of the child block, this would return an ErrNotFound
@@ -1221,17 +1178,13 @@ func TestMalformedHamt(t *testing.T) {
1221
1178
bcat (b (0x80 + 2 ), // array(2)
1222
1179
bcat (b (0x40 + 1 ), b (0x03 )), // bytes(1) "\x03" (bitmap)
1223
1180
bcat (b (0x80 + 2 ), // array(2)
1224
- bcat (b (0xa0 + 1 ), // map(1)
1225
- bcat (b (0x60 + 1 ), b (0x31 )), // string(1) "1"
1226
- bcat (b (0x80 + 1 ), // array(1)
1227
- bcat (b (0x80 + 2 ), // array(2)
1228
- bcat (b (0x40 + 2 ), []byte {0x00 , 0x01 }), // bytes(2) "\x0001"
1229
- bcat (b (0x40 + 1 ), b (0xff ))))), // bytes(1) "\xff"
1230
- bcat (b (0xa0 + 1 ), // map(1)
1231
- bcat (b (0x60 + 1 ), b (0x30 )), // string(1) "0"
1232
- bcat (b (0xd8 ), b (0x2a ), // tag(42)
1233
- b (0x58 ), b (0x27 ), // bytes(39)
1234
- ccidBytes ))))) // cid
1181
+ bcat (b (0x80 + 1 ), // array(1)
1182
+ bcat (b (0x80 + 2 ), // array(2)
1183
+ bcat (b (0x40 + 2 ), []byte {0x00 , 0x01 }), // bytes(2) "\x0001"
1184
+ bcat (b (0x40 + 1 ), b (0xff )))), // bytes(1) "\xff"
1185
+ bcat (b (0xd8 ), b (0x2a ), // tag(42)
1186
+ b (0x58 ), b (0x27 ), // bytes(39)
1187
+ ccidBytes )))) // cid
1235
1188
1236
1189
vg , err = load ().FindRaw (ctx , string ([]byte {0x00 , 0x01 }))
1237
1190
// without validation of the child block, this would return an ErrNotFound
0 commit comments