diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 55805cf13e..e3b478d414 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,22 +34,12 @@ Then you need `git`, if you don't have that yet: https://git-scm.com/ ### Windows -Building on Windows versions 8+ is supported out of the box +Building on Windows is a pain, but is possible see our CI/Windows build machine prerequisites here [Windows-2022 GH image](https://github.com/actions/runner-images/blob/main/images/win/Windows2022-Readme.md) ### Linux -1. Pick your favorite package manager. -1. Install `python` -1. Install `gcc` -1. Install `g++` -1. Install `make` -1. Depending on your distro, you might need to install `hunspell` and `hunspell-` (e.g. `hunspell-en-au`) - -If you are using a Debian based Linux distribution gcc, g++ and make can be installed as part of the `build-essential` package using - -``` -apt install build-essential -``` +1. Install build tools `apt install build-essential cmake` (this installs make, g++, gcc) +2. Depending on your distro, you might need to install `hunspell` and `hunspell-` (e.g. `hunspell-en-au`) ### All platforms diff --git a/ts/node/sql.ts b/ts/node/sql.ts index 2964865b87..0a12bd7e64 100644 --- a/ts/node/sql.ts +++ b/ts/node/sql.ts @@ -4,10 +4,12 @@ import path from 'path'; import * as BetterSqlite3 from '@signalapp/better-sqlite3'; import rimraf from 'rimraf'; +import { base64_variants, from_base64, to_hex } from 'libsodium-wrappers-sumo'; import { chunk, compact, difference, + differenceBy, forEach, fromPairs, isArray, @@ -20,7 +22,6 @@ import { omit, uniq, } from 'lodash'; -import { base64_variants, from_base64, to_hex } from 'libsodium-wrappers-sumo'; import { ConversationAttributes } from '../models/conversationAttributes'; import { PubKey } from '../session/types/PubKey'; // checked - only node @@ -60,11 +61,13 @@ import { } from '../types/sqlSharedTypes'; import { KNOWN_BLINDED_KEYS_ITEM, SettingsKey } from '../data/settings-key'; +import { Quote } from '../receiver/types'; import { getSQLCipherIntegrityCheck, openAndMigrateDatabase, updateSchema, } from './migration/signalMigrations'; +import { configDumpData } from './sql_calls/config_dump'; import { assertGlobalInstance, assertGlobalInstanceOrInstance, @@ -72,8 +75,6 @@ import { initDbInstanceWith, isInstanceInitialized, } from './sqlInstance'; -import { configDumpData } from './sql_calls/config_dump'; -import { Quote } from '../receiver/types'; // eslint:disable: function-name non-literal-fs-path @@ -620,11 +621,28 @@ function getAllConversations() { .prepare(`SELECT * FROM ${CONVERSATIONS_TABLE} ORDER BY id ASC;`) .all(); - return (rows || []).map(m => { - const unreadCount = getUnreadCountByConversation(m.id) || 0; - const mentionedUsStillUnread = !!getFirstUnreadMessageWithMention(m.id); - return formatRowOfConversation(m, 'getAllConversations', unreadCount, mentionedUsStillUnread); + const formatted = compact( + (rows || []).map(m => { + const unreadCount = getUnreadCountByConversation(m.id) || 0; + const mentionedUsStillUnread = !!getFirstUnreadMessageWithMention(m.id); + return formatRowOfConversation(m, 'getAllConversations', unreadCount, mentionedUsStillUnread); + }) + ); + + const invalidOnLoad = formatted.filter(m => { + return isString(m.id) && m.id.startsWith('05') && m.id.includes(' '); }); + + if (!isEmpty(invalidOnLoad)) { + const idsInvalid = invalidOnLoad.map(m => m.id); + console.info( + 'getAllConversations removing those conversations with invalid ids before load', + idsInvalid + ); + removeConversation(idsInvalid); + } + + return differenceBy(formatted, invalidOnLoad, c => c.id); } function getPubkeysInPublicConversation(conversationId: string) { diff --git a/ts/session/utils/libsession/libsession_utils_contacts.ts b/ts/session/utils/libsession/libsession_utils_contacts.ts index 0db5442c35..f955f192d6 100644 --- a/ts/session/utils/libsession/libsession_utils_contacts.ts +++ b/ts/session/utils/libsession/libsession_utils_contacts.ts @@ -29,6 +29,11 @@ const mappedContactWrapperValues = new Map(); * We want to sync the message request status so we need to allow a contact even if it's not approved, did not approve us and is not blocked. */ function isContactToStoreInWrapper(convo: ConversationModel): boolean { + try { + PubKey.cast(convo.id as string); + } catch (e) { + return false; + } return !convo.isMe() && convo.isPrivate() && convo.isActive() && !PubKey.isBlinded(convo.id); } diff --git a/ts/test/session/unit/libsession_wrapper/libsession_wrapper_contacts_test.ts b/ts/test/session/unit/libsession_wrapper/libsession_wrapper_contacts_test.ts index b5763c03a6..f839159d31 100644 --- a/ts/test/session/unit/libsession_wrapper/libsession_wrapper_contacts_test.ts +++ b/ts/test/session/unit/libsession_wrapper/libsession_wrapper_contacts_test.ts @@ -13,7 +13,7 @@ describe('libsession_contacts', () => { describe('filter contacts for wrapper', () => { const ourNumber = '051234567890acbdef'; const validArgs = { - id: '051111567890acbdef', + id: '050123456789abcdef050123456789abcdef0123456789abcdef050123456789ab', type: ConversationTypeEnum.PRIVATE, isApproved: true, active_at: 123, @@ -137,6 +137,58 @@ describe('libsession_contacts', () => { ).to.be.eq(false); }); + it('excludes contacts not matching a pubkey syntax (space in middle)', () => { + const validIdWithSpaceInIt = + '050123456789abcdef050123456789 bcdef0123456789abcdef050123456789ab'; // len 66 but has a ' ' in the middle + expect( + SessionUtilContact.isContactToStoreInWrapper( + new ConversationModel({ + ...validArgs, + id: validIdWithSpaceInIt, + } as any) + ) + ).to.be.eq(false); + }); + + it('excludes contacts not matching a pubkey syntax (space at the end)', () => { + const validIdWithSpaceInIt = + '050123456789abcdef050123456789abcdef0123456789abcdef050123456789a '; // len 66 but has a ' ' at the end + expect( + SessionUtilContact.isContactToStoreInWrapper( + new ConversationModel({ + ...validArgs, + id: validIdWithSpaceInIt, + } as any) + ) + ).to.be.eq(false); + }); + + it('excludes contacts not matching a pubkey syntax (space at the start)', () => { + const validIdWithSpaceInIt = + ' 050123456789abcdef050123456789abcdef0123456789abcdef050123456789ab'; // len 66 but has a ' ' at the start + expect( + SessionUtilContact.isContactToStoreInWrapper( + new ConversationModel({ + ...validArgs, + id: validIdWithSpaceInIt, + } as any) + ) + ).to.be.eq(false); + }); + + it('excludes contacts not matching a pubkey syntax (non hex char)', () => { + const validIdWithSpaceInIt = + '050123456789abcdef050123456789abcdef0123456789abcdef050123456789aU'; // len 66 but has 'U' at the end + expect( + SessionUtilContact.isContactToStoreInWrapper( + new ConversationModel({ + ...validArgs, + id: validIdWithSpaceInIt, + } as any) + ) + ).to.be.eq(false); + }); + it('includes approved only by them ', () => { expect( SessionUtilContact.isContactToStoreInWrapper(