From b745f1f9024d8600408a6ca34e6eb66377e89f2c Mon Sep 17 00:00:00 2001 From: AsamK Date: Sun, 22 Aug 2021 08:54:21 +0200 Subject: [PATCH] Trim zero bytes from profile fields --- .../org/asamk/signal/manager/util/ProfileUtils.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/org/asamk/signal/manager/util/ProfileUtils.java b/lib/src/main/java/org/asamk/signal/manager/util/ProfileUtils.java index 213f516c..f6f76c2c 100644 --- a/lib/src/main/java/org/asamk/signal/manager/util/ProfileUtils.java +++ b/lib/src/main/java/org/asamk/signal/manager/util/ProfileUtils.java @@ -18,8 +18,8 @@ public class ProfileUtils { var profileCipher = new ProfileCipher(profileKey); try { var name = decrypt(encryptedProfile.getName(), profileCipher); - var about = decrypt(encryptedProfile.getAbout(), profileCipher); - var aboutEmoji = decrypt(encryptedProfile.getAboutEmoji(), profileCipher); + var about = trimZeros(decrypt(encryptedProfile.getAbout(), profileCipher)); + var aboutEmoji = trimZeros(decrypt(encryptedProfile.getAboutEmoji(), profileCipher)); final var nameParts = splitName(name); return new Profile(System.currentTimeMillis(), @@ -95,4 +95,13 @@ public class ProfileUtils { return new Pair<>(parts[0], parts[1]); } } + + static String trimZeros(String str) { + if (str == null) { + return null; + } + + int pos = str.indexOf(0); + return pos == -1 ? str : str.substring(0, pos); + } }