From 91e42aba6dd51a0e389235360283b44785cb8cb1 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Wed, 23 Feb 2022 15:27:44 +0100 Subject: [PATCH] fix(@dekstop/chat): creating a chat with numeric only crashes the app Fixes #4860 --- src/app_service/service/contacts/async_tasks.nim | 2 -- src/app_service/service/contacts/service.nim | 12 ++++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/app_service/service/contacts/async_tasks.nim b/src/app_service/service/contacts/async_tasks.nim index b4663a7634..3f32ce46d0 100644 --- a/src/app_service/service/contacts/async_tasks.nim +++ b/src/app_service/service/contacts/async_tasks.nim @@ -8,8 +8,6 @@ include ../../../app/core/tasks/common # Async lookup ENS contact ################################################# -const PK_LENGTH_0X_INCLUDED = 132 - type LookupContactTaskArg = ref object of QObjectTaskArg value: string diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index a820c3c2d1..4480a862f2 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -16,6 +16,8 @@ import ../../../backend/utils as status_utils export contacts_dto, status_update_dto, contact_details +const PK_LENGTH_0X_INCLUDED = 132 + include async_tasks logScope: @@ -211,6 +213,16 @@ QtObject: result = self.fetchContact(id) if result.id.len == 0: + if(not id.startsWith("0x")): + debug "id is not in a hex format" + return + + var num64: int64 + let parsedChars = parseHex(id, num64) + if(parsedChars != PK_LENGTH_0X_INCLUDED): + debug "id doesn't have expected lenght" + return + let alias = self.generateAlias(id) let identicon = self.generateIdenticonURL(id) result = ContactsDto(