ComposioHQ/composio · error · KeyringError
CFDataGetBytePtr returned NULL
Error message
CFDataGetBytePtr returned NULL
What it means
CFDataGetBytePtr returned NULL while extracting bytes from a CFData result (e.g. a secret returned by SecItemCopyMatching). KeyringError kind 'PlatformFailure'.
Source
Thrown at ts/packages/cli-keyring/src/stores/macos-security-ffi.ts:372
const buf = new Uint8Array(4096);
const ok = cf.symbols.CFStringGetCString(
cfString,
buf,
BigInt(buf.byteLength),
kCFStringEncodingUTF8
);
if (!ok) return '<unrepresentable>';
const end = buf.indexOf(0);
return textDecoder.decode(buf.subarray(0, end === -1 ? buf.byteLength : end));
}
/** Extract raw bytes from a CFData. */
function cfDataToBytes(cfData: bigint): Uint8Array {
const length = Number(cf.symbols.CFDataGetLength(cfData));
if (length === 0) return new Uint8Array();
const bytePtr = cf.symbols.CFDataGetBytePtr(cfData);
if (bytePtr === 0n) {
throw new KeyringError({
kind: 'PlatformFailure',
cause: new Error('CFDataGetBytePtr returned NULL'),
});
}
// CFData storage is a real heap pointer (never tagged), so the
// BigInt value fits in JS safe integer range and we can hand it to
// toArrayBuffer via Number. Copy into JS-owned memory so we don't
// retain the CFData longer than necessary.
const view = new Uint8Array(toArrayBuffer(Number(bytePtr) as unknown as never, 0, length));
return new Uint8Array(view);
}
/** Build a mutable CFDictionary. */
function cfMutableDict(pool: CFPool): bigint {
const dict = cf.symbols.CFDictionaryCreateMutable(
0n,
0n,
K.kCFTypeDictionaryKeyCallBacks,View on GitHub (pinned to 64b1b85502)
Solutions
- Retry once — often transient
- Delete and re-create the problematic keychain item if consistently reproducible
- Report with item details to maintainers
Defensive patterns
Strategy: retry
Try / catch
catch (e) { if (e instanceof KeyringError && e.kind === 'PlatformFailure' && /CFDataGetBytePtr/.test(String(e.cause))) { return withRetry(fn, 2); } throw e; } Prevention
- Re-create persistently failing keychain items
- Log item attributes when the failure repeats
When it happens
Trigger: Reading secret data from the macOS keychain when the CFData reports a non-zero length but yields a NULL byte pointer.
Common situations: Corrupted or unusual keychain items; edge cases in OS-provided data objects; rare platform failures.
Related errors
- PlatformFailure
- dlsym(${name}) failed
- CFStringCreateWithBytes returned NULL
- CFDictionaryCreateMutable returned NULL
- Invalid
AI-assisted analysis of ComposioHQ/composio@64b1b85502 (2026-08-28).
Data as JSON: /api/errors/7fdfc2d1ce666e57.
Report an issue: GitHub.