SPARK-2380: insertPicture(): Check if the file extension is a known image type

This commit is contained in:
Sergey Ponomarev
2026-01-08 02:28:33 +02:00
committed by Guus der Kinderen
parent ef36f0ac6e
commit cd011e6ce4

View File

@ -33,6 +33,7 @@ import javax.swing.text.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.net.URI;
import java.net.URLConnection;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.*;
@ -386,6 +387,11 @@ public class MessageEntry extends TimeStampedEntry
if (path == null || path.isEmpty()) {
return false;
}
// Check if the file extension is a known image type
String mimeType = URLConnection.getFileNameMap().getContentTypeFor(path);
if (mimeType == null || !mimeType.startsWith("image/")) {
return false;
}
try (final CloseableHttpClient httpClient =
HttpClients.custom()