kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fix crash when processing invalid mentions.
rodzic
f490d1f6d2
commit
6770d21cf7
|
@ -76,6 +76,10 @@ public final class MentionUtil {
|
|||
int bodyIndex = 0;
|
||||
|
||||
for (Mention mention : sortedMentions) {
|
||||
if (invalidMention(body, mention)) {
|
||||
return new UpdatedBodyAndMentions(body, Collections.emptyList());
|
||||
}
|
||||
|
||||
updatedBody.append(body.subSequence(bodyIndex, mention.getStart()));
|
||||
CharSequence replaceWith = replacementTextGenerator.apply(mention);
|
||||
Mention updatedMention = new Mention(mention.getRecipientId(), updatedBody.length(), replaceWith.length());
|
||||
|
@ -139,6 +143,13 @@ public final class MentionUtil {
|
|||
throw new IllegalArgumentException("Unknown mention setting: " + mentionSetting);
|
||||
}
|
||||
|
||||
private static boolean invalidMention(@NonNull CharSequence body, @NonNull Mention mention) {
|
||||
int start = mention.getStart();
|
||||
int length = mention.getLength();
|
||||
|
||||
return start < 0 || length < 0 || (start + length) > body.length();
|
||||
}
|
||||
|
||||
public static class UpdatedBodyAndMentions {
|
||||
@Nullable private final CharSequence body;
|
||||
@NonNull private final List<Mention> mentions;
|
||||
|
|
|
@ -69,6 +69,8 @@ public class MentionUtilTest_updateBodyAndMentionsWithPlaceholders {
|
|||
builder().text("middle 🤡👍🏾 👨🏼🤝👨🏽 ").mention("a").text(" 👍🏾 middle 👩👩👦👦").build(),
|
||||
builder().text("start ").mention("emoji 🩳").build(),
|
||||
builder().text("start ").mention("emoji 🩳").text(" middle ").mention("emoji 🩳").text(" end").build(),
|
||||
|
||||
{ "message", Collections.singletonList(new Mention(RecipientId.from(1), 30, 5)), "message", Collections.<Mention>emptyList() }
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue