Handle oversized attachment dimensions (#2157)

This commit is contained in:
Wu Shuwen 2026-10-28 15:27:56 +08:00 committed by GitHub
parent 49aaef000f
commit 1e878f3845
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View File

@ -313,8 +313,15 @@ public class SendCommand implements JsonRpcLocalCommand {
+ dimension
+ ") expected 'WIDTHxHEIGHT'");
}
dimensions.add(new Message.AttachmentDimensions(Integer.parseInt(matcher.group(1)),
Integer.parseInt(matcher.group(2))));
try {
dimensions.add(new Message.AttachmentDimensions(Integer.parseInt(matcher.group(1)),
Integer.parseInt(matcher.group(2))));
} catch (NumberFormatException e) {
throw new UserErrorException("Invalid attachment dimensions syntax ("
+ dimension
+ ") expected 'WIDTHxHEIGHT' with positive 32-bit integer values",
e);
}
}
return dimensions;
}

View File

@ -105,6 +105,20 @@ class SendCommandParsingTest {
}
}
@Test
void rejectsAttachmentDimensionsOutsideIntegerRange() {
for (final var value : List.of("2147483648x1", "1x2147483648")) {
assertThrows(UserErrorException.class, () -> send(namespace(List.of(value))), value);
}
}
@Test
void acceptsMaximumPositiveAttachmentDimensions() throws Exception {
final var message = send(namespace(List.of("2147483647x2147483647")));
assertEquals(List.of(new Message.AttachmentDimensions(Integer.MAX_VALUE, Integer.MAX_VALUE)),
message.attachmentDimensions());
}
@Test
void rejectsMalformedBlurHashesBeforeSending() {
// Wrong length for its size digit, an unknown size digit, too short.