mirror of
https://github.com/AsamK/signal-cli.git
synced 2026-11-29 08:55:48 +00:00
Handle out of range mention, text style and sticker numbers (#2170)
Like the attachment dimensions, the numbers matched by \d+ were parsed with Integer.parseInt, so a value outside the int range failed with a NumberFormatException instead of the command's UserErrorException. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b1389cca4f
commit
a7c769615b
2 files changed
+53
-7
No files matched your search
@@ -391,9 +391,15 @@ public class SendCommand implements JsonRpcLocalCommand {
|
||||
+ mention
|
||||
+ ") expected 'start:length:recipientNumber'");
|
||||
}
|
||||
mentions.add(new Message.Mention(CommandUtil.getSingleRecipientIdentifier(matcher.group(3), selfNumber),
|
||||
Integer.parseInt(matcher.group(1)),
|
||||
Integer.parseInt(matcher.group(2))));
|
||||
try {
|
||||
mentions.add(new Message.Mention(CommandUtil.getSingleRecipientIdentifier(matcher.group(3), selfNumber),
|
||||
Integer.parseInt(matcher.group(1)),
|
||||
Integer.parseInt(matcher.group(2))));
|
||||
} catch (NumberFormatException e) {
|
||||
throw new UserErrorException("Invalid mention syntax ("
|
||||
+ mention
|
||||
+ ") expected 'start:length:recipientNumber' with 32-bit integer values", e);
|
||||
}
|
||||
}
|
||||
return mentions;
|
||||
}
|
||||
@@ -414,9 +420,15 @@ public class SendCommand implements JsonRpcLocalCommand {
|
||||
if (style == null) {
|
||||
throw new UserErrorException("Invalid style: " + matcher.group(3));
|
||||
}
|
||||
textStyles.add(new TextStyle(style,
|
||||
Integer.parseInt(matcher.group(1)),
|
||||
Integer.parseInt(matcher.group(2))));
|
||||
try {
|
||||
textStyles.add(new TextStyle(style,
|
||||
Integer.parseInt(matcher.group(1)),
|
||||
Integer.parseInt(matcher.group(2))));
|
||||
} catch (NumberFormatException e) {
|
||||
throw new UserErrorException("Invalid textStyle syntax ("
|
||||
+ textStyle
|
||||
+ ") expected 'start:length:STYLE' with 32-bit integer values", e);
|
||||
}
|
||||
}
|
||||
return textStyles;
|
||||
}
|
||||
@@ -429,7 +441,13 @@ public class SendCommand implements JsonRpcLocalCommand {
|
||||
+ stickerString
|
||||
+ ") expected 'stickerPackId:stickerId'");
|
||||
}
|
||||
return new Message.Sticker(Hex.toByteArray(matcher.group(1)), Integer.parseInt(matcher.group(2)));
|
||||
try {
|
||||
return new Message.Sticker(Hex.toByteArray(matcher.group(1)), Integer.parseInt(matcher.group(2)));
|
||||
} catch (NumberFormatException e) {
|
||||
throw new UserErrorException("Invalid sticker syntax ("
|
||||
+ stickerString
|
||||
+ ") expected 'stickerPackId:stickerId' with a 32-bit integer stickerId", e);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Message.Quote.Attachment> parseQuoteAttachments(
|
||||
|
||||
@@ -115,6 +115,34 @@ class SendCommandParsingTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsMentionAndTextStyleNumbersOutsideIntegerRange() {
|
||||
for (final var range : List.of("2147483648:1", "0:2147483648")) {
|
||||
assertThrows(UserErrorException.class,
|
||||
() -> send(new JsonRpcNamespace(Map.of("noteToSelf",
|
||||
true,
|
||||
"message",
|
||||
"hello",
|
||||
"textStyle",
|
||||
List.of(range + ":BOLD")))),
|
||||
range);
|
||||
assertThrows(UserErrorException.class,
|
||||
() -> send(new JsonRpcNamespace(Map.of("noteToSelf",
|
||||
true,
|
||||
"message",
|
||||
"hello",
|
||||
"mention",
|
||||
List.of(range + ":+15550000000")))),
|
||||
range);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsStickerIdOutsideIntegerRange() {
|
||||
assertThrows(UserErrorException.class,
|
||||
() -> send(new JsonRpcNamespace(Map.of("noteToSelf", true, "sticker", "00ff:2147483648"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptsMaximumPositiveAttachmentDimensions() throws Exception {
|
||||
final var message = send(namespace(List.of("2147483647x2147483647")));
|
||||
|
||||
Reference in new issue
Block a user