From 082878aade3ef7edb311d5fd933b047682657de7 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sat, 30 Jul 2022 18:04:28 -0500 Subject: [PATCH] Handle null images --- .../java/org/dynmap/storage/aws_s3/AWSS3MapStorage.java | 3 ++- .../org/dynmap/storage/mssql/MicrosoftSQLMapStorage.java | 6 +++++- .../org/dynmap/storage/postgresql/PostgreSQLMapStorage.java | 6 +++++- .../java/org/dynmap/storage/sqllte/SQLiteMapStorage.java | 6 +++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/DynmapCore/src/main/java/org/dynmap/storage/aws_s3/AWSS3MapStorage.java b/DynmapCore/src/main/java/org/dynmap/storage/aws_s3/AWSS3MapStorage.java index d3a9d6f0..e954279f 100644 --- a/DynmapCore/src/main/java/org/dynmap/storage/aws_s3/AWSS3MapStorage.java +++ b/DynmapCore/src/main/java/org/dynmap/storage/aws_s3/AWSS3MapStorage.java @@ -101,7 +101,8 @@ public class AWSS3MapStorage extends MapStorage { GetObjectResponse rsp = obj.getResponse(); TileRead tr = new TileRead(); byte[] buf = obj.getBytes(); - tr.image = new BufferInputStream(buf); + if (buf == null) { return null; } + tr.image = new BufferInputStream(buf); tr.format = ImageEncoding.fromContentType(rsp.getContentType()); Map meta = rsp.getMetadata(); String v = meta.get("x-dynmap-hash"); diff --git a/DynmapCore/src/main/java/org/dynmap/storage/mssql/MicrosoftSQLMapStorage.java b/DynmapCore/src/main/java/org/dynmap/storage/mssql/MicrosoftSQLMapStorage.java index 15be1fcd..6cfd3b78 100644 --- a/DynmapCore/src/main/java/org/dynmap/storage/mssql/MicrosoftSQLMapStorage.java +++ b/DynmapCore/src/main/java/org/dynmap/storage/mssql/MicrosoftSQLMapStorage.java @@ -132,7 +132,11 @@ public class MicrosoftSQLMapStorage extends MapStorage { rslt.lastModified = rs.getLong("LastUpdate"); rslt.format = MapType.ImageEncoding.fromOrd(rs.getInt("Format")); byte[] img = rs.getBytes("Image"); - rslt.image = new BufferInputStream(img); + if (img == null) { + rslt = null; + } else { + rslt.image = new BufferInputStream(img); + } } rs.close(); stmt.close(); diff --git a/DynmapCore/src/main/java/org/dynmap/storage/postgresql/PostgreSQLMapStorage.java b/DynmapCore/src/main/java/org/dynmap/storage/postgresql/PostgreSQLMapStorage.java index c45a20c0..5506aec9 100644 --- a/DynmapCore/src/main/java/org/dynmap/storage/postgresql/PostgreSQLMapStorage.java +++ b/DynmapCore/src/main/java/org/dynmap/storage/postgresql/PostgreSQLMapStorage.java @@ -138,7 +138,11 @@ public class PostgreSQLMapStorage extends MapStorage { rslt.lastModified = rs.getLong("LastUpdate"); rslt.format = MapType.ImageEncoding.fromOrd(rs.getInt("Format")); byte[] img = rs.getBytes("Image"); - rslt.image = new BufferInputStream(img); + if (img == null) { + rslt = null; + } else { + rslt.image = new BufferInputStream(img); + } } rs.close(); stmt.close(); diff --git a/DynmapCore/src/main/java/org/dynmap/storage/sqllte/SQLiteMapStorage.java b/DynmapCore/src/main/java/org/dynmap/storage/sqllte/SQLiteMapStorage.java index 98184560..f0580cef 100644 --- a/DynmapCore/src/main/java/org/dynmap/storage/sqllte/SQLiteMapStorage.java +++ b/DynmapCore/src/main/java/org/dynmap/storage/sqllte/SQLiteMapStorage.java @@ -129,7 +129,11 @@ public class SQLiteMapStorage extends MapStorage { // Trim trailing zeros from padding by BLOB field while((len > 0) && (img[len-1] == '\0')) len--; } - rslt.image = new BufferInputStream(img, len); + if (img == null) { + rslt = null; + } else { + rslt.image = new BufferInputStream(img, len); + } } rs.close(); stmt.close();