Skip to content

Main content

BSON Cstring Zero Byte Rejection Tool

Check the zero-byte restriction on a BSON cstring payload before adding its terminator; no UTF-8 validation.

Loading tool…

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

  1. Enter bytes. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. 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 fieldMeaning and unitsAccepted input
bytesBytesRequired. Array of safe integer; maximum items 256.
Output fieldInterpretationReturned shape
acceptablePayloadTrue only when the unterminated payload has no zero octet.Required. Boolean.
firstZeroIndexZero-based first zero octet, or -1 if none.Required. Safe integer.
json
{
  "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

  1. Calculation and input contract: encode/bson-cstring-zero-byte-rejection — tool.io

  2. BSON specification 1.1 — BSON

Similar or alternative tools