Implement limits to image size and load times (#1790)

* Implement limits to image size and load times
 - Prevents issues caused by users attempting to load large images
 - Implements #1729

* Check dimensions given before attempting to load image
This commit is contained in:
Jordan
2022-06-13 08:04:59 +01:00
committed by GitHub
parent 8377b0987c
commit 02a6bb9b27
4 changed files with 49 additions and 9 deletions

View File

@@ -647,16 +647,21 @@ public class Settings extends Config {
}
@Comment({"Web/HTTP connection related settings"})
public static class WEB {
@Comment({
"The web interface for clipboards",
" - All schematics are anonymous and private",
" - Downloads can be deleted by the user",
" - Supports clipboard uploads, downloads and saves",
})
@Comment({"The web interface for clipboards", " - All schematics are anonymous and private", " - Downloads can be deleted by the user", " - Supports clipboard uploads, downloads and saves",})
public String URL = "https://schem.intellectualsites.com/fawe/";
@Comment("The maximum amount of time in seconds the plugin can attempt to load images for.")
public int MAX_IMAGE_LOAD_TIME = 5;
@Comment({
"The maximum size (width x length) an image being loaded can be.",
" - 8294400 is 3840x2160"
})
public int MAX_IMAGE_SIZE = 8294400;
}
public static class EXTENT {

View File

@@ -4,6 +4,7 @@ import com.fastasyncworldedit.core.Fawe;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.history.changeset.FaweStreamChangeSet;
import com.fastasyncworldedit.core.internal.exception.FaweException;
import com.fastasyncworldedit.core.internal.io.AbstractDelegateOutputStream;
import com.fastasyncworldedit.core.internal.io.FaweInputStream;
import com.fastasyncworldedit.core.internal.io.FaweOutputStream;
@@ -532,6 +533,8 @@ public class MainUtil {
public static BufferedImage toRGB(BufferedImage src) {
if (src == null) {
return src;
} else if ((long) src.getWidth() * src.getHeight() > Settings.settings().WEB.MAX_IMAGE_SIZE) {
throw new FaweException(Caption.of("fawe.web.image.load.size.too-large", Settings.settings().WEB.MAX_IMAGE_SIZE));
}
BufferedImage img = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = img.createGraphics();