Add more validation to server icons. Closes #828
This commit is contained in:
parent
dae96ac18b
commit
5f7963b0c4
@ -4,6 +4,9 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import com.google.common.io.Files;
|
||||
import gnu.trove.map.TMap;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
@ -11,6 +14,7 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import javax.imageio.ImageIO;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.ProxyConfig;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@ -63,7 +67,21 @@ public class Configuration implements ProxyConfig
|
||||
{
|
||||
try
|
||||
{
|
||||
favicon = "data:image/png;base64," + BaseEncoding.base64().encode( Files.toByteArray( fav ) );
|
||||
BufferedImage image = ImageIO.read( fav );
|
||||
if ( image.getHeight() == 64 && image.getWidth() == 64 )
|
||||
{
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
ImageIO.write( image, "png", bytes );
|
||||
favicon = "data:image/png;base64," + BaseEncoding.base64().encode( bytes.toByteArray() );
|
||||
if ( favicon.length() > Short.MAX_VALUE )
|
||||
{
|
||||
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Favicon file too large for server to process" );
|
||||
favicon = null;
|
||||
}
|
||||
} else
|
||||
{
|
||||
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Server icon must be exactly 64x64 pixels" );
|
||||
}
|
||||
} catch ( IOException ex )
|
||||
{
|
||||
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Could not load server icon", ex );
|
||||
|
Loading…
Reference in New Issue
Block a user