gchq/CyberChef · error · OperationError
${err.toString()}
Error message
${err.toString()} What it means
Generic catch-all thrown by BSONDeserialise.run when the underlying bson deserialize() throws on the input bytes. BSON is a strict binary format with length-prefixed documents, typed fields, and terminator bytes; any structural defect (truncation, bad length prefix, unknown/invalid element type, bad UTF-8 string) causes the library to throw, and the original Error.toString() is forwarded verbatim as the OperationError message.
Source
Thrown at src/core/operations/BSONDeserialise.mjs:43
this.infoURL = "https://wikipedia.org/wiki/BSON";
this.inputType = "ArrayBuffer";
this.outputType = "string";
this.args = [];
}
/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
if (!input.byteLength) return "";
try {
const data = deserialize(new Uint8Array(input));
return JSON.stringify(data, null, 2);
} catch (err) {
throw new OperationError(err.toString());
}
}
}
export default BSONDeserialise;
View on GitHub (pinned to 4290ea7539)
Solutions
- Confirm the input is genuine BSON binary produced by a BSON serialiser.
- If you have JSON text, use BSONSerialise's inverse or a JSON parser instead.
- Inspect the forwarded Error.toString() message for the specific BSON defect.
- Re-serialize the source document and re-copy the full buffer.
Example fix
// before - feeding JSON text
chef.bSONDeserialise('{"a":1}');
// after - feeding BSON bytes from BSONSerialise
const bsonBytes = chef.bSONSerialise('{"a":1}');
chef.bSONDeserialise(bsonBytes); Defensive patterns
Strategy: try-catch
Validate before calling
function looksLikeBSON(buf) {
if (!(buf instanceof ArrayBuffer) || buf.byteLength < 5) return false;
const dv = new DataView(buf);
const docLen = dv.getInt32(0, true);
return docLen >= 5 && docLen <= buf.byteLength;
} Type guard
function isLikelyBSON(buf) {
if (!(buf instanceof ArrayBuffer) || buf.byteLength < 5) return false;
const dv = new DataView(buf);
const docLen = dv.getInt32(0, true);
return docLen >= 5 && docLen <= buf.byteLength;
} Try / catch
try {
chef.bSONDeserialise(buf);
} catch (e) {
if (/bson|truncat|length|type/i.test(e.message)) {
throw new Error(`Not valid BSON: ${e.message}`);
}
throw e;
} Prevention
- Confirm the bytes came from a BSON serialiser, not raw JSON text.
- Validate the BSON length prefix against the buffer size.
- Forward the original library error to diagnose the exact field defect.
When it happens
Trigger: Feeding non-BSON bytes (e.g. JSON text, MessagePack, or random binary), a truncated BSON document, a document whose declared length does not match the buffer, or a string field with invalid UTF-8.
Common situations: Piping JSON text into BSONDeserialise by mistake; copy-paste truncating the binary buffer; upstream 'From Hex' with odd-length or corrupted hex.
Related errors
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/8479ab3dc511aaeb.
Report an issue: GitHub.