Skip to content

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

web: Incorrect math for determining total number of chunks causes erroneous assertation that there is one more chunk in certain conditions.

Chloe Oletto2c1d8b0eeac7
diff --git a/apps/web/src/interfaces/fs.ts b/apps/web/src/interfaces/fs.ts
index 62b9f7894..77c27629f 100644
--- a/apps/web/src/interfaces/fs.ts
+++ b/apps/web/src/interfaces/fs.ts
@@ -454,7 +454,7 @@ export async function checkUpload(
expectedSize: number
) {
const size = await getUploadedFileSize(filename);
- const totalChunks = Math.ceil(size / chunkSize);
+ const totalChunks = Math.ceil(size / (chunkSize + ABYTES));
const decryptedLength = size - totalChunks * ABYTES;
const error =
size === 0
@@ -520,7 +520,7 @@ async function downloadFile(
throw new Error(error);
}
- const totalChunks = Math.ceil(size / chunkSize);
+ const totalChunks = Math.ceil(size / (chunkSize + ABYTES));
const decryptedLength = size - totalChunks * ABYTES;
if (attachment && attachment.size !== decryptedLength) {
const error = `File length mismatch. Expected ${attachment.size} but got ${decryptedLength} bytes. Please upload this file again from the attachment manager. (File hash: ${filename})`;