-
Notifications
You must be signed in to change notification settings - Fork 453
[CDRIVER-6017] Tweak visitor behavior when finding corrupt BSON #2019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
e33f48a
349a9be
976d7d1
b9eccf0
efe9654
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,25 +185,54 @@ typedef struct { | |
|
||
|
||
/** | ||
* bson_validate_flags_t: | ||
* @brief Flags an error code for BSON validation functions. | ||
* | ||
* This enumeration is used for validation of BSON documents. It allows | ||
* selective control on what you wish to validate. | ||
* Pass these flags bits to control the behavior of the `bson_validate` family | ||
* of functions. | ||
* | ||
* %BSON_VALIDATE_NONE: No additional validation occurs. | ||
* %BSON_VALIDATE_UTF8: Check that strings are valid UTF-8. | ||
* %BSON_VALIDATE_DOLLAR_KEYS: Check that keys do not start with $. | ||
* %BSON_VALIDATE_DOT_KEYS: Check that keys do not contain a period. | ||
* %BSON_VALIDATE_UTF8_ALLOW_NULL: Allow NUL bytes in UTF-8 text. | ||
* %BSON_VALIDATE_EMPTY_KEYS: Prohibit zero-length field names | ||
* Additionally, if validation fails, then the error code set on a `bson_error_t` | ||
* will have the value corresponding to the reason that validation failed. | ||
*/ | ||
typedef enum { | ||
/** | ||
* @brief No special validation behavior specified. | ||
*/ | ||
BSON_VALIDATE_NONE = 0, | ||
/** | ||
* @brief This flag has no effect | ||
* | ||
* @note Because invalid UTF-8 text is always invalid in BSON, the `bson_validate` | ||
* function will always reject invalid UTF-8 data as corrupt BSON. | ||
*/ | ||
BSON_VALIDATE_UTF8 = (1 << 0), | ||
/** | ||
* @brief Check that element keys do not begin with an ASCII dollar `$` | ||
*/ | ||
BSON_VALIDATE_DOLLAR_KEYS = (1 << 1), | ||
/** | ||
* @brief Check that element keys do not contain an ASCII period `.` | ||
*/ | ||
BSON_VALIDATE_DOT_KEYS = (1 << 2), | ||
/** | ||
* @brief If set then it is *not* an error for a UTF-8 string to contain | ||
* embedded null characters. | ||
* | ||
* By default, `bson_validate` APIs will reject BSON UTF-8 elements that | ||
* contain embedded null characters. | ||
*/ | ||
BSON_VALIDATE_UTF8_ALLOW_NULL = (1 << 3), | ||
/** | ||
* @brief Check that no element key is a zero-length empty string. | ||
*/ | ||
BSON_VALIDATE_EMPTY_KEYS = (1 << 4), | ||
/** | ||
* @brief This is not a flag that controls behavior, but is instead used to indicate | ||
* that a BSON document is corrupted in some way. This is the value that will | ||
* appear as an error code. | ||
* | ||
* Passing this as a flag has no effect. | ||
*/ | ||
BSON_VALIDATE_CORRUPT = (1 << 30), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we reuse
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, but I considered adding a |
||
} bson_validate_flags_t; | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we take this opportunity to extend test suite coverage of the
.visit_corrupt
callback function to account for these new checks? atm there only seems to be a single test case. Perhaps theVALIDATE_TEST
macro can be extended to also check.visit_corrupt
callback behavior?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think this is a good idea.