Update max message length check

This commit is contained in:
trevor-signal
2025-07-30 11:09:38 -04:00
committed by GitHub
parent cde504957a
commit 7ef40c64c4
3 changed files with 25 additions and 6 deletions
+2 -2
View File
@@ -81,6 +81,7 @@ import { FUN_STATIC_EMOJI_CLASS } from './fun/FunEmoji';
import { useFunEmojiSearch } from './fun/useFunEmojiSearch';
import type { EmojiCompletionOptions } from '../quill/emoji/completion';
import { useFunEmojiLocalizer } from './fun/useFunEmojiLocalizer';
import { MAX_BODY_ATTACHMENT_BYTE_LENGTH } from '../util/longAttachment';
const log = createLogger('CompositionInput');
@@ -158,7 +159,6 @@ export type Props = Readonly<{
onCloseLinkPreview?(conversationId: string): unknown;
}>;
const MAX_LENGTH = 64 * 1024;
const BASE_CLASS_NAME = 'module-composition-input';
export function CompositionInput(props: Props): React.ReactElement {
@@ -612,7 +612,7 @@ export function CompositionInput(props: Props): React.ReactElement {
node.attributes.removeNamedItem('style');
}
if (text.length > MAX_LENGTH) {
if (Buffer.byteLength(text) > MAX_BODY_ATTACHMENT_BYTE_LENGTH) {
quill.history.undo();
propsRef.current.onTextTooLong();
return;
+14 -1
View File
@@ -55,7 +55,11 @@ import {
} from '../../util/editHelpers';
import { getMessageSentTimestamp } from '../../util/getMessageSentTimestamp';
import { isSignalConversation } from '../../util/isSignalConversation';
import { isBodyTooLong, trimBody } from '../../util/longAttachment';
import {
isBodyTooLong,
MAX_BODY_ATTACHMENT_BYTE_LENGTH,
trimBody,
} from '../../util/longAttachment';
import {
markFailed,
saveErrorsOnMessage,
@@ -607,6 +611,15 @@ async function getMessageSendData({
targetTimestamp,
});
if (
maybeLongAttachment &&
maybeLongAttachment.size > MAX_BODY_ATTACHMENT_BYTE_LENGTH
) {
throw new Error(
`Body attachment too long for send: ${maybeLongAttachment.size}`
);
}
if (body && isBodyTooLong(body)) {
body = trimBody(body);
}
+9 -3
View File
@@ -3,16 +3,22 @@
import { unicodeSlice } from './unicodeSlice';
const LONG_ATTACHMENT_LIMIT = 2048;
const KIBIBYTE = 1024;
const MAX_MESSAGE_BODY_BYTE_LENGTH = 2 * KIBIBYTE;
export const MAX_BODY_ATTACHMENT_BYTE_LENGTH = 64 * KIBIBYTE;
export function isBodyTooLong(
body: string,
length = LONG_ATTACHMENT_LIMIT
length = MAX_MESSAGE_BODY_BYTE_LENGTH
): boolean {
return Buffer.byteLength(body) > length;
}
export function trimBody(body: string, length = LONG_ATTACHMENT_LIMIT): string {
export function trimBody(
body: string,
length = MAX_MESSAGE_BODY_BYTE_LENGTH
): string {
const sliced = unicodeSlice(body, 0, length);
if (sliced.length > 0) {