From 12d40aa94e7795f4fa72fd22be6f1a9f51f4432f Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 13 May 2021 13:32:52 +1000 Subject: [PATCH] Fix attachment extension vnd (#1628) * allow openoffice document extension and don't use * allow opendocument to be shared with the extension rather than mimetype Fixes #1593 * allow message without padding * add test for odt files --- preload.js | 4 ---- ts/session/crypto/BufferPadding.ts | 3 ++- ts/test/types/Attachment_test.ts | 9 +++++++++ ts/types/Attachment.ts | 7 ++++++- ts/types/MIME.ts | 1 + 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/preload.js b/preload.js index f3a9437e0..2ff7d47c3 100644 --- a/preload.js +++ b/preload.js @@ -353,8 +353,6 @@ window.clipboard = clipboard; window.seedNodeList = JSON.parse(config.seedNodeList); -const { OnionPaths } = require('./ts/session/onions'); - const { locale: localFromEnv } = config; window.i18n = i18n.setup(localFromEnv, localeMessages); @@ -375,8 +373,6 @@ window.moment.updateLocale(localeSetForMoment, { }, }); -window.OnionPaths = OnionPaths; - window.libsession = require('./ts/session'); window.models = require('./ts/models'); diff --git a/ts/session/crypto/BufferPadding.ts b/ts/session/crypto/BufferPadding.ts index ea640ac7f..5658cd7c0 100644 --- a/ts/session/crypto/BufferPadding.ts +++ b/ts/session/crypto/BufferPadding.ts @@ -19,7 +19,8 @@ export function removeMessagePadding(paddedData: ArrayBuffer): ArrayBuffer { plaintext.set(paddedPlaintext.subarray(0, i)); return plaintext.buffer; } else if (paddedPlaintext[i] !== PADDING_BYTE) { - throw new Error('Invalid padding'); + window.log.warn('got a message without padding... Letting it through for now'); + return paddedPlaintext; } } diff --git a/ts/test/types/Attachment_test.ts b/ts/test/types/Attachment_test.ts index f3a521c8d..55bf2dd56 100644 --- a/ts/test/types/Attachment_test.ts +++ b/ts/test/types/Attachment_test.ts @@ -27,6 +27,15 @@ describe('Attachment', () => { }; assert.strictEqual(Attachment.getFileExtension(input), 'mov'); }); + + it('should return file extension for application files', () => { + const input: Attachment.AttachmentType = { + fileName: 'funny-cat.odt', + url: 'funny-cat.odt', + contentType: MIME.ODT, + }; + assert.strictEqual(Attachment.getFileExtension(input), 'odt'); + }); }); describe('getSuggestedFilename', () => { diff --git a/ts/types/Attachment.ts b/ts/types/Attachment.ts index d4da15da3..b162c267a 100644 --- a/ts/types/Attachment.ts +++ b/ts/types/Attachment.ts @@ -361,7 +361,12 @@ export const getSuggestedFilenameSending = ({ export const getFileExtension = (attachment: AttachmentType): string | undefined => { // we override textplain to the extension of the file - if (!attachment.contentType || attachment.contentType === 'text/plain') { + // for contenttype starting with application, the mimetype is probably wrong so just use the extension of the file instead + if ( + !attachment.contentType || + attachment.contentType === 'text/plain' || + attachment.contentType.startsWith('application') + ) { if (attachment.fileName?.length) { const dotLastIndex = attachment.fileName.lastIndexOf('.'); if (dotLastIndex !== -1) { diff --git a/ts/types/MIME.ts b/ts/types/MIME.ts index 049095cad..ec74665ab 100644 --- a/ts/types/MIME.ts +++ b/ts/types/MIME.ts @@ -14,6 +14,7 @@ export const IMAGE_WEBP = 'image/webp' as MIMEType; export const IMAGE_PNG = 'image/png' as MIMEType; export const VIDEO_MP4 = 'video/mp4' as MIMEType; export const VIDEO_QUICKTIME = 'video/quicktime' as MIMEType; +export const ODT = 'application/vnd.oasis.opendocument.spreadsheet' as MIMEType; export const isJPEG = (value: MIMEType): boolean => value === 'image/jpeg'; export const isImage = (value: MIMEType): boolean =>