Description
Return firstZeroIndex from bytes.indexOf(0), or -1 if absent, and acceptablePayload true only when no zero is present.
BSON names can use a cstring terminated by a zero octet, so zero cannot occur inside that payload. Payload admissibility is only one constraint; UTF-8 and the complete document structure need independent validation.
Return firstZeroIndex from bytes.indexOf(0), or -1 if absent, and acceptablePayload true only when no zero is present.
When to use this tool
Use BSON Cstring Zero Byte Rejection when checking a supplied cstring payload for embedded zero bytes.
How to use the tool and how it works
- Enter bytes. Use the units and conventions below.
- Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
- Read acceptablePayload, firstZeroIndex. Inspect acceptablePayload before interpreting the associated values.
Require every supplied byte value in [0,255]. Return firstZeroIndex from bytes.indexOf(0), or -1 if absent, and acceptablePayload true only when no zero is present.1
A BSON cstring excludes zero within its payload and ends with a zero terminator. This check concerns only the supplied payload.2
| Input field | Meaning and units | Accepted input |
|---|---|---|
| bytes | Bytes | Required. Array of safe integer; maximum items 256. |
| Output field | Interpretation | Returned shape |
|---|---|---|
| acceptablePayload | True only when the unterminated payload has no zero octet. | Required. Boolean. |
| firstZeroIndex | Zero-based first zero octet, or -1 if none. | Required. Safe integer. |
{
"input": {
"bytes": [
65,
66
]
},
"output": {
"acceptablePayload": true,
"firstZeroIndex": -1
}
} Limitations and assumptions
- This checks an unterminated BSON cstring payload, so its eventual terminator is not part of the supplied array. UTF-8 validity and complete BSON structure are not checked.
- Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.
Alternative or Complementary methods
Use a complete BSON implementation for actual UTF-8 names, terminators, sizes and document validation.
References
Similar or alternative tools
- DER Integer Sign Padding Octet
Canonicalize an unsigned magnitude’s positive DER INTEGER content and add a sign-protection octet when needed.
- Encoding: Netstring Length Prefix
Return its decimal spelling followed by a colon as prefix.