Ensure long message trimming is unicode-aware
This commit is contained in:
parent
8655244261
commit
08342a9f43
6 changed files with 54 additions and 31 deletions
|
@ -154,6 +154,7 @@ import {
|
|||
import { checkOurPniIdentityKey } from '../util/checkOurPniIdentityKey';
|
||||
import { CallLinkUpdateSyncType } from '../types/CallLink';
|
||||
import { bytesToUuid } from '../util/uuidToBytes';
|
||||
import { isBodyTooLong } from '../util/longAttachment';
|
||||
|
||||
const GROUPV2_ID_LENGTH = 32;
|
||||
const RETRY_TIMEOUT = 2 * 60 * 1000;
|
||||
|
@ -2157,7 +2158,8 @@ export default class MessageReceiver
|
|||
envelope: ProcessedEnvelope,
|
||||
sentContainer: ProcessedSent
|
||||
) {
|
||||
log.info('MessageReceiver.handleSentMessage', getEnvelopeId(envelope));
|
||||
const logId = `MessageReceiver.handleSentMessage/${getEnvelopeId(envelope)}`;
|
||||
log.info(logId);
|
||||
|
||||
logUnexpectedUrgentValue(envelope, 'sentSync');
|
||||
|
||||
|
@ -2172,7 +2174,7 @@ export default class MessageReceiver
|
|||
} = sentContainer;
|
||||
|
||||
if (!msg) {
|
||||
throw new Error('MessageReceiver.handleSentMessage: message was falsey!');
|
||||
throw new Error(`${logId}: message was falsey!`);
|
||||
}
|
||||
|
||||
// TODO: DESKTOP-5804
|
||||
|
@ -2180,14 +2182,18 @@ export default class MessageReceiver
|
|||
if (destinationServiceId) {
|
||||
await this.handleEndSession(envelope, destinationServiceId);
|
||||
} else {
|
||||
throw new Error(
|
||||
'MessageReceiver.handleSentMessage: Cannot end session with falsey destination'
|
||||
);
|
||||
throw new Error(`${logId}: Cannot end session with falsey destination`);
|
||||
}
|
||||
}
|
||||
|
||||
const message = this.processDecrypted(envelope, msg);
|
||||
|
||||
if (message.body && isBodyTooLong(message.body)) {
|
||||
const length = Buffer.byteLength(message.body);
|
||||
this.removeFromCache(envelope);
|
||||
log.warn(`${logId}: Dropping too-long message. Length: ${length}`);
|
||||
}
|
||||
|
||||
const ev = new SentEvent(
|
||||
{
|
||||
envelopeId: envelope.id,
|
||||
|
@ -2487,12 +2493,12 @@ export default class MessageReceiver
|
|||
envelope: UnsealedEnvelope,
|
||||
msg: Proto.IDataMessage
|
||||
): Promise<void> {
|
||||
const logId = getEnvelopeId(envelope);
|
||||
log.info('MessageReceiver.handleDataMessage', logId);
|
||||
const logId = `MessageReceiver.handleDataMessage/${getEnvelopeId(envelope)}`;
|
||||
log.info(logId);
|
||||
|
||||
if (getStoriesBlocked() && msg.storyContext) {
|
||||
log.info(
|
||||
`MessageReceiver.handleDataMessage/${logId}: Dropping incoming dataMessage with storyContext field`
|
||||
`${logId}: Dropping incoming dataMessage with storyContext field`
|
||||
);
|
||||
this.removeFromCache(envelope);
|
||||
return;
|
||||
|
@ -2501,15 +2507,10 @@ export default class MessageReceiver
|
|||
let p: Promise<void> = Promise.resolve();
|
||||
const { sourceServiceId: sourceAci } = envelope;
|
||||
if (!sourceAci) {
|
||||
throw new Error(
|
||||
'MessageReceiver.handleDataMessage: sourceAci was falsey'
|
||||
);
|
||||
throw new Error(`${logId}: sourceAci was falsey`);
|
||||
}
|
||||
|
||||
strictAssert(
|
||||
isAciString(sourceAci),
|
||||
'MessageReceiver.handleDataMessage: received message from PNI'
|
||||
);
|
||||
strictAssert(isAciString(sourceAci), `${logId}: received message from PNI`);
|
||||
|
||||
if (this.isInvalidGroupData(msg, envelope)) {
|
||||
this.removeFromCache(envelope);
|
||||
|
@ -2542,10 +2543,10 @@ export default class MessageReceiver
|
|||
);
|
||||
|
||||
if (isProfileKeyUpdate) {
|
||||
return this.dispatchAndWait(logId, ev);
|
||||
return this.dispatchAndWait(getEnvelopeId(envelope), ev);
|
||||
}
|
||||
|
||||
drop(this.dispatchAndWait(logId, ev));
|
||||
drop(this.dispatchAndWait(getEnvelopeId(envelope), ev));
|
||||
}
|
||||
await p;
|
||||
|
||||
|
@ -2573,13 +2574,17 @@ export default class MessageReceiver
|
|||
const isBlocked = groupId ? this.isGroupBlocked(groupId) : false;
|
||||
|
||||
if (groupId && isBlocked) {
|
||||
log.warn(
|
||||
`Message ${getEnvelopeId(envelope)} ignored; destined for blocked group`
|
||||
);
|
||||
log.warn(`${logId}: message ignored; destined for blocked group`);
|
||||
this.removeFromCache(envelope);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (message.body && isBodyTooLong(message.body)) {
|
||||
const length = Buffer.byteLength(message.body);
|
||||
this.removeFromCache(envelope);
|
||||
log.warn(`${logId}: Dropping too-long message. Length: ${length}`);
|
||||
}
|
||||
|
||||
const ev = new MessageEvent(
|
||||
{
|
||||
envelopeId: envelope.id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue