Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

chore: sanity checks for chunk.data

thecodrrb26e2967a5d3
diff --git a/apps/web/packages/nncrypto/index.ts b/apps/web/packages/nncrypto/index.ts
index 70853e184..e9c3a2130 100644
--- a/apps/web/packages/nncrypto/index.ts
+++ b/apps/web/packages/nncrypto/index.ts
@@ -66,6 +66,7 @@ export class NNCrypto implements INNCrypto {
if (!chunk) break;
const { data, final } = chunk;
+ if (!data) break;
const encryptedChunk: Chunk = {
data: encryptionStream.write(data, final),
@@ -90,6 +91,8 @@ export class NNCrypto implements INNCrypto {
if (!chunk) break;
const { data, final } = chunk;
+ if (!data) break;
+
const decryptedChunk: Chunk = {
data: decryptionStream.read(data),
final,
diff --git a/apps/web/packages/nncryptoworker/index.ts b/apps/web/packages/nncryptoworker/index.ts
index 8cbd6f117..577933b9c 100644
--- a/apps/web/packages/nncryptoworker/index.ts
+++ b/apps/web/packages/nncryptoworker/index.ts
@@ -136,7 +136,7 @@ export class NNCryptoWorker implements INNCrypto {
const { type } = ev.data;
if (type === readEventType) {
const chunk = await stream.read();
- if (!chunk || !this.worker) return;
+ if (!chunk || !this.worker || !chunk.data) return;
this.worker.postMessage({ type, data: chunk }, [chunk.data.buffer]);
} else if (type === writeEventType) {
const chunk = ev.data.data as Chunk;
diff --git a/apps/web/packages/nncryptoworker/src/workerstream.ts b/apps/web/packages/nncryptoworker/src/workerstream.ts
index b76ac43fe..797444615 100644
--- a/apps/web/packages/nncryptoworker/src/workerstream.ts
+++ b/apps/web/packages/nncryptoworker/src/workerstream.ts
@@ -24,6 +24,7 @@ export default class WorkerStream
* @param {Uint8Array} chunk
*/
async write(chunk: Chunk): Promise<void> {
+ if (!chunk.data) return;
postMessage({ type: `${this.id}:write`, data: chunk }, [chunk.data.buffer]);
}
}