Skip to content

Commit 89703c3

Browse files
authored
fix(rivetkit): copy Buffer to Uint8Array in ensureUint8Array to fix .slice() semantics (#4506)
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes
1 parent 099f97d commit 89703c3

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

rivetkit-typescript/packages/rivetkit/src/drivers/file-system/sqlite-runtime.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ export function ensureUint8Array(
216216
fieldName: string,
217217
): Uint8Array {
218218
if (value instanceof Uint8Array) {
219+
// Buffer (from better-sqlite3) extends Uint8Array but overrides
220+
// .slice() to return a view instead of a copy. This breaks
221+
// downstream libraries (vbare, cbor-x) that rely on
222+
// Uint8Array.prototype.slice() semantics. Copy into a plain
223+
// Uint8Array so .slice() always copies.
224+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(value)) {
225+
const copy = new Uint8Array(value.byteLength);
226+
copy.set(value);
227+
return copy;
228+
}
219229
return value;
220230
}
221231
if (value instanceof ArrayBuffer) {

0 commit comments

Comments
 (0)