Skip to content

Commit

Permalink
Enforce safe access to the user shared array buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Jan 2, 2025
1 parent 2fd2a4c commit 3a18645
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions read.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,17 +401,23 @@ export function addReadMethods(
keySize = this.writeKey(id, keyBytes, 4);
}
};
setKeyBytes();
let sharedBuffer = getUserSharedBuffer(
env.address,
keySize,
defaultBuffer,
options?.callback,
);
sharedBuffer.notify = () => {
let userSharedBuffers =
this._userSharedBuffers || (this._userSharedBuffers = new Map());
let sharedBuffer = userSharedBuffers.get(id.toString());
if (!sharedBuffer) {
setKeyBytes();
return notifyUserCallbacks(env.address, keySize);
};
sharedBuffer = getUserSharedBuffer(
env.address,
keySize,
defaultBuffer,
options?.callback,
);
userSharedBuffers.set(id.toString(), sharedBuffer);
sharedBuffer.notify = () => {
setKeyBytes();
return notifyUserCallbacks(env.address, keySize);
};
}
return sharedBuffer;
},

Expand Down

0 comments on commit 3a18645

Please sign in to comment.