From 55df2d2090a6afd6a2ccdabb213cd21264142582 Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Mon, 12 Aug 2024 15:17:10 -0500 Subject: [PATCH] Ensure outgoing filesize limit considers padding and encryption Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com> --- ts/util/processAttachment.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ts/util/processAttachment.ts b/ts/util/processAttachment.ts index c939169322..fe18ee9277 100644 --- a/ts/util/processAttachment.ts +++ b/ts/util/processAttachment.ts @@ -21,6 +21,7 @@ import { handleVideoAttachment } from './handleVideoAttachment'; import { isHeic, stringToMIMEType } from '../types/MIME'; import { ToastType } from '../types/Toast'; import { isImageTypeSupported, isVideoTypeSupported } from './GoogleChrome'; +import { getAttachmentCiphertextLength } from '../AttachmentCrypto'; export async function processAttachment( file: File, @@ -79,10 +80,11 @@ export async function processAttachment( function isAttachmentSizeOkay(attachment: Readonly): boolean { const limitKb = getMaximumOutgoingAttachmentSizeInKb(getRemoteConfigValue); - // this needs to be cast properly - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - if ((attachment.data.byteLength / KIBIBYTE).toFixed(4) >= limitKb) { + const limitBytes = + getMaximumOutgoingAttachmentSizeInKb(getRemoteConfigValue) * KIBIBYTE; + + const paddedAndEncryptedSize = getAttachmentCiphertextLength(attachment.size); + if (paddedAndEncryptedSize > limitBytes) { window.reduxActions.toast.showToast({ toastType: ToastType.FileSize, parameters: getRenderDetailsForLimit(limitKb),