File tree Expand file tree Collapse file tree 5 files changed +35
-25
lines changed
source/bson-binary-vector Expand file tree Collapse file tree 5 files changed +35
-25
lines changed Original file line number Diff line number Diff line change @@ -184,6 +184,8 @@ Drivers MUST validate vector metadata and raise an error if any invariant is vio
184184
185185- Padding MUST be 0 for all dtypes where padding doesn’t apply, and MUST be within \[ 0, 7\] for PACKED_BIT.
186186- A PACKED_BIT vector MUST NOT be empty if padding is in the range \[ 1, 7\] .
187+ - When unpacking binary data into a FLOAT32 Vector structure, the length of the binary data following the dtype and
188+ padding MUST be a multiple of 4 bytes.
187189
188190Drivers MUST perform this validation when a numeric vector and padding are provided through the API, and when unpacking
189191binary data (BSON or similar) into a Vector structure.
@@ -242,3 +244,9 @@ See the [README](tests/README.md) for tests.
242244 you want to store or transmit binary data more efficiently by grouping 8 bits into a single byte (uint8). For an
243245 example in Python, see
244246 [ numpy.unpackbits] ( https://numpy.org/doc/2.0/reference/generated/numpy.unpackbits.html#numpy.unpackbits ) .
247+
248+ ## Changelog
249+
250+ - 2025-02-04: Update validation for decoding into a FLOAT32 vector.
251+
252+ - 2024-11-01: BSON Binary Subtype 9 accepted DRIVERS-2926 (#1708 )
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ Each JSON file contains three top-level keys.
2929
3030- ` description ` : string describing the test.
3131- ` valid ` : boolean indicating if the vector, dtype, and padding should be considered a valid input.
32- - ` vector ` : list of numbers
32+ - ` vector ` : (required if valid is true) list of numbers
3333- ` dtype_hex ` : string defining the data type in hex (e.g. "0x10", "0x27")
3434- ` dtype_alias ` : (optional) string defining the data dtype, perhaps as Enum.
3535- ` padding ` : (optional) integer for byte padding. Defaults to 0.
@@ -50,7 +50,10 @@ MUST assert that the input float array is the same after encoding and decoding.
5050
5151#### To prove correct in an invalid case (` valid:false ` ), one MUST
5252
53- - raise an exception when attempting to encode a document from the numeric values, dtype, and padding.
53+ - if the vector field is present, raise an exception when attempting to encode a document from the numeric values,
54+ dtype, and padding.
55+ - if the canonical_bson field is present, raise an exception when attempting to deserialize it into the corresponding
56+ numeric values, as the field contains corrupted data.
5457
5558## FAQ
5659
Original file line number Diff line number Diff line change 4444 "vector" : [127.0 , 7.0 ],
4545 "dtype_hex" : " 0x27" ,
4646 "dtype_alias" : " FLOAT32" ,
47- "padding" : 3
47+ "padding" : 3 ,
48+ "canonical_bson" : " 1C00000005766563746F72000A0000000927030000FE420000E04000"
49+ },
50+ {
51+ "description" : " Insufficient vector data with 3 bytes FLOAT32" ,
52+ "valid" : false ,
53+ "dtype_hex" : " 0x27" ,
54+ "dtype_alias" : " FLOAT32" ,
55+ "canonical_bson" : " 1700000005766563746F7200050000000927002A2A2A00"
56+ },
57+ {
58+ "description" : " Insufficient vector data with 5 bytes FLOAT32" ,
59+ "valid" : false ,
60+ "dtype_hex" : " 0x27" ,
61+ "dtype_alias" : " FLOAT32" ,
62+ "canonical_bson" : " 1900000005766563746F7200070000000927002A2A2A2A2A00"
4863 }
4964 ]
5065}
51-
Original file line number Diff line number Diff line change 4242 "vector" : [127 , 7 ],
4343 "dtype_hex" : " 0x03" ,
4444 "dtype_alias" : " INT8" ,
45- "padding" : 3
45+ "padding" : 3 ,
46+ "canonical_bson" : " 1600000005766563746F7200040000000903037F0700"
4647 },
4748 {
4849 "description" : " INT8 with float inputs" ,
5455 }
5556 ]
5657}
57-
Original file line number Diff line number Diff line change 88 "vector" : [],
99 "dtype_hex" : " 0x10" ,
1010 "dtype_alias" : " PACKED_BIT" ,
11- "padding" : 1
11+ "padding" : 1 ,
12+ "canonical_bson" : " 1400000005766563746F72000200000009100100"
1213 },
1314 {
1415 "description" : " Simple Vector PACKED_BIT" ,
6162 "dtype_alias" : " PACKED_BIT" ,
6263 "padding" : 0
6364 },
64- {
65- "description" : " Padding specified with no vector data PACKED_BIT" ,
66- "valid" : false ,
67- "vector" : [],
68- "dtype_hex" : " 0x10" ,
69- "dtype_alias" : " PACKED_BIT" ,
70- "padding" : 1
71- },
7265 {
7366 "description" : " Exceeding maximum padding PACKED_BIT" ,
7467 "valid" : false ,
7568 "vector" : [1 ],
7669 "dtype_hex" : " 0x10" ,
7770 "dtype_alias" : " PACKED_BIT" ,
78- "padding" : 8
71+ "padding" : 8 ,
72+ "canonical_bson" : " 1500000005766563746F7200030000000910080100"
7973 },
8074 {
8175 "description" : " Negative padding PACKED_BIT" ,
8478 "dtype_hex" : " 0x10" ,
8579 "dtype_alias" : " PACKED_BIT" ,
8680 "padding" : -1
87- },
88- {
89- "description" : " Vector with float values PACKED_BIT" ,
90- "valid" : false ,
91- "vector" : [127.5 ],
92- "dtype_hex" : " 0x10" ,
93- "dtype_alias" : " PACKED_BIT" ,
94- "padding" : 0
9581 }
9682 ]
9783}
98-
You can’t perform that action at this time.
0 commit comments