{"record":{"id":"7fdfc2d1ce666e57","repo":"ComposioHQ/composio","slug":"cfdatagetbyteptr-returned-null","errorCode":null,"errorMessage":"CFDataGetBytePtr returned NULL","messagePattern":"CFDataGetBytePtr returned NULL","errorType":"exception","errorClass":"KeyringError","httpStatus":null,"severity":"error","filePath":"ts/packages/cli-keyring/src/stores/macos-security-ffi.ts","lineNumber":372,"sourceCode":"  const buf = new Uint8Array(4096);\n  const ok = cf.symbols.CFStringGetCString(\n    cfString,\n    buf,\n    BigInt(buf.byteLength),\n    kCFStringEncodingUTF8\n  );\n  if (!ok) return '<unrepresentable>';\n  const end = buf.indexOf(0);\n  return textDecoder.decode(buf.subarray(0, end === -1 ? buf.byteLength : end));\n}\n\n/** Extract raw bytes from a CFData. */\nfunction cfDataToBytes(cfData: bigint): Uint8Array {\n  const length = Number(cf.symbols.CFDataGetLength(cfData));\n  if (length === 0) return new Uint8Array();\n  const bytePtr = cf.symbols.CFDataGetBytePtr(cfData);\n  if (bytePtr === 0n) {\n    throw new KeyringError({\n      kind: 'PlatformFailure',\n      cause: new Error('CFDataGetBytePtr returned NULL'),\n    });\n  }\n  // CFData storage is a real heap pointer (never tagged), so the\n  // BigInt value fits in JS safe integer range and we can hand it to\n  // toArrayBuffer via Number. Copy into JS-owned memory so we don't\n  // retain the CFData longer than necessary.\n  const view = new Uint8Array(toArrayBuffer(Number(bytePtr) as unknown as never, 0, length));\n  return new Uint8Array(view);\n}\n\n/** Build a mutable CFDictionary. */\nfunction cfMutableDict(pool: CFPool): bigint {\n  const dict = cf.symbols.CFDictionaryCreateMutable(\n    0n,\n    0n,\n    K.kCFTypeDictionaryKeyCallBacks,","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/ComposioHQ/composio/blob/64b1b85502b1beeb2379e6c9e8bf1104504fa637/ts/packages/cli-keyring/src/stores/macos-security-ffi.ts#L354-L390","documentation":"CFDataGetBytePtr returned NULL while extracting bytes from a CFData result (e.g. a secret returned by SecItemCopyMatching). KeyringError kind 'PlatformFailure'.","triggerScenarios":"Reading secret data from the macOS keychain when the CFData reports a non-zero length but yields a NULL byte pointer.","commonSituations":"Corrupted or unusual keychain items; edge cases in OS-provided data objects; rare platform failures.","solutions":["Retry once — often transient","Delete and re-create the problematic keychain item if consistently reproducible","Report with item details to maintainers"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (e) { if (e instanceof KeyringError && e.kind === 'PlatformFailure' && /CFDataGetBytePtr/.test(String(e.cause))) { return withRetry(fn, 2); } throw e; }","preventionTips":["Re-create persistently failing keychain items","Log item attributes when the failure repeats"],"tags":["keyring","macos","ffi","native","typescript"],"backgroundTag":"native-api-returned-null","analyzedSha":"64b1b85502b1beeb2379e6c9e8bf1104504fa637","analyzedAt":"2026-08-28T15:39:33.623Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}