Avoid mute timeouts with invalid delay values

This commit is contained in:
trevor-signal 2025-02-01 21:21:14 -05:00 committed by GitHub
parent a793285e3c
commit 2001e4d7b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View file

@ -26,7 +26,7 @@ import { getNotificationTextForMessage } from '../util/getNotificationTextForMes
import { getNotificationDataForMessage } from '../util/getNotificationDataForMessage';
import type { ProfileNameChangeType } from '../util/getStringForProfileChange';
import type { AttachmentType, ThumbnailType } from '../types/Attachment';
import { toDayMillis } from '../util/timestamp';
import { MAX_SAFE_TIMEOUT_DELAY, toDayMillis } from '../util/timestamp';
import { areWeAdmin } from '../util/areWeAdmin';
import { isBlocked } from '../util/isBlocked';
import { getAboutText } from '../util/getAboutText';
@ -5386,6 +5386,13 @@ export class ConversationModel extends window.Backbone
return;
}
if (delay > MAX_SAFE_TIMEOUT_DELAY) {
log.warn(
'startMuteTimer: timeout is larger than maximum setTimeout delay'
);
return;
}
this.#muteTimer = setTimeout(() => this.setMuteExpiration(0), delay);
}
}

View file

@ -210,6 +210,8 @@ export function formatDate(
export const MAX_SAFE_DATE = 8640000000000000;
export const MIN_SAFE_DATE = -8640000000000000;
export const MAX_SAFE_TIMEOUT_DELAY = 2147483647; // max 32-bit signed integer
export function toBoundedDate(timestamp: number): Date {
return new Date(Math.max(MIN_SAFE_DATE, Math.min(timestamp, MAX_SAFE_DATE)));
}