-
Type: Bug
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
C Drivers
Current bson_validate* functions return an offset to the element relative to the innermost document containing said element. This leads to misleading offsets when validating BSON documents containing sub-documents, as would often be the case when validating dollar keys:
// clang-format off // { // "x": 1, // "v": { // "$numberInt": "123" // } // } uint8_t bytes[] = { 0x28, 0x00, 0x00, 0x00, 0x10, // Offset: 4 0x78, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, // Offset: 11 0x76, 0x00, 0x19, 0x00, 0x00, 0x00, 0x02, // Offset: 18 (<--) 0x24, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x49, 0x6e, 0x74, 0x00, 0x04, 0x00, 0x00, 0x00, 0x31, 0x32, 0x33, 0x00, 0x00, 0x00 }; // clang-format on bson_t bson; assert (bson_init_static (&bson, bytes, sizeof (bytes))); size_t offset; assert (!bson_validate (&bson, BSON_VALIDATE_DOLLAR_KEYS, &offset)); assert (offset == 4u); // !?
The expected (and useful) byte offset should be 18, relative to the start of the outermost document being validated. Instead, the returned byte offset is 4, relative to the start of the sub-document.