Skip to content

Commit 1d1f385

Browse files
committed
Fixed crash when working with ImageMessages
1 parent da4131e commit 1d1f385

File tree

5 files changed

+5
-4
lines changed

5 files changed

+5
-4
lines changed
0 Bytes
Binary file not shown.
535 Bytes
Binary file not shown.

src/main/java/icu/jnet/whatsjava/encryption/MediaEncryption.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static byte[] decrypt(byte[] mediaKey, String url, String mediaType) {
3535

3636
// Download encrypted media
3737
byte[] encryptedMedia = Utils.urlToEncryptedMedia(url);
38-
38+
3939
if(encryptedMedia != null) {
4040
byte[] file = Arrays.copyOfRange(encryptedMedia, 0, encryptedMedia.length - 10);
4141
byte[] mac = Arrays.copyOfRange(encryptedMedia, encryptedMedia.length - 10, encryptedMedia.length);
@@ -45,7 +45,7 @@ public static byte[] decrypt(byte[] mediaKey, String url, String mediaType) {
4545

4646
// Validate macKey of mediaKeyExpanded with mac key of the encrypted media
4747
byte[] hmacSign = Utils.signHMAC(macKey, message);
48-
48+
4949
// Media validated
5050
if(Arrays.equals(mac, Arrays.copyOfRange(hmacSign, 0, 10))) {
5151
return AES.decrypt(file, cipherKey, iv);

src/main/java/icu/jnet/whatsjava/messages/WAMessageParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static Object[] jsonToObjects(String json) {
3434
String typeValue = attributes.get("type").getAsString();
3535

3636
// Contains node content
37-
JsonArray childrenArray = node.get(2).isJsonArray() ? node.get(2).getAsJsonArray() : null;
37+
JsonArray childrenArray = node.get(2).isJsonArray() ? node.get(2).getAsJsonArray() : new JsonArray();
3838

3939
switch (typeValue) {
4040
case "message":

src/main/java/icu/jnet/whatsjava/messages/generic/WAImageMessage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public WAImageMessage(WebMessageInfo message) {
3333

3434
// Convert byte array to BufferedImage and load full resolution image
3535
this.jpegThumbnail = MediaEncryption.convertBytesToImage(imageMessage.getJpegThumbnail().toByteArray());
36-
this.jpegFullResolution = MediaEncryption.convertBytesToImage(MediaEncryption.decrypt(mediaKey, url, MediaEncryption.MEDIA_TYPE_IMAGE));
36+
byte[] decryptedBytes = MediaEncryption.decrypt(mediaKey, url, MediaEncryption.MEDIA_TYPE_IMAGE);
37+
this.jpegFullResolution = decryptedBytes != null ? MediaEncryption.convertBytesToImage(decryptedBytes) : jpegThumbnail;
3738
}
3839

3940
public String getMimetype() {

0 commit comments

Comments
 (0)