do not allow empty cover images
authorNiki Roo <niki@nikiroo.be>
Fri, 15 May 2020 11:00:21 +0000 (13:00 +0200)
committerNiki Roo <niki@nikiroo.be>
Fri, 15 May 2020 11:00:21 +0000 (13:00 +0200)
src/be/nikiroo/fanfix/library/LocalLibrary.java
src/be/nikiroo/fanfix/library/WebLibrary.java
src/be/nikiroo/fanfix/searchable/Fanfiction.java
src/be/nikiroo/fanfix/searchable/MangaLel.java
src/be/nikiroo/fanfix/supported/BasicSupportHelper.java
src/be/nikiroo/fanfix/supported/BasicSupportImages.java
src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java
src/be/nikiroo/fanfix/supported/Cbz.java
src/be/nikiroo/fanfix/supported/Epub.java
src/be/nikiroo/fanfix/supported/FimfictionApi.java
src/be/nikiroo/fanfix/supported/MangaLel.java

index 7220a3951de137f99a4a11ecc7e5f5b119abb3c1..f655d4d03bb43b5df69d00fc8b30b2adbad6c113 100644 (file)
@@ -254,7 +254,13 @@ public class LocalLibrary extends BasicLibrary {
                                        in = new FileInputStream(cover);
                                        try {
                                                synchronized (lock) {
-                                                       sourceCovers.put(source, new Image(in));
+                                                       Image img = new Image(in);
+                                                       if (img.getSize() == 0) {
+                                                               img.close();
+                                                               throw new IOException(
+                                                                               "Empty image not accepted");
+                                                       }
+                                                       sourceCovers.put(source, img);
                                                }
                                        } finally {
                                                in.close();
@@ -298,7 +304,13 @@ public class LocalLibrary extends BasicLibrary {
                                in = new FileInputStream(cover);
                                try {
                                        synchronized (lock) {
-                                               authorCovers.put(author, new Image(in));
+                                               Image img = new Image(in);
+                                               if (img.getSize() == 0) {
+                                                       img.close();
+                                                       throw new IOException(
+                                                                       "Empty image not accepted");
+                                               }
+                                               authorCovers.put(author, img);
                                        }
                                } finally {
                                        in.close();
index 0f2510dd544218279d8ddcaa1beae3ad097d631c..9af38e2b6bd1c7ccb565ca6f244e31ef42f40746 100644 (file)
@@ -174,6 +174,7 @@ public class WebLibrary extends BasicLibrary {
                try {
                        Image img = new Image(in);
                        if (img.getSize() > 0) {
+                               img.close();
                                return img;
                        }
 
@@ -189,6 +190,7 @@ public class WebLibrary extends BasicLibrary {
                try {
                        Image img = new Image(in);
                        if (img.getSize() > 0) {
+                               img.close();
                                return img;
                        }
 
@@ -204,6 +206,7 @@ public class WebLibrary extends BasicLibrary {
                try {
                        Image img = new Image(in);
                        if (img.getSize() > 0) {
+                               img.close();
                                return img;
                        }
 
index e2fba1ff404f17d2a23bc18defbc2b03d7a425e3..cbc927bcc2d981b028311be59fa2d1ba7c152542 100644 (file)
@@ -287,7 +287,13 @@ class Fanfiction extends BasicSearchable {
                                        try {
                                                InputStream in = Instance.getInstance().getCache().open(new URL(coverUrl), getSupport(), true);
                                                try {
-                                                       meta.setCover(new Image(in));
+                                                       Image img = new Image(in);
+                                                       if (img.getSize() == 0) {
+                                                               img.close();
+                                                               throw new IOException(
+                                                                               "Empty image not accepted");
+                                                       }
+                                                       meta.setCover(img);
                                                } finally {
                                                        in.close();
                                                }
index 5ba21a0e1ce25b799dc0b9a6d14d3a447135ef01..354edb435ef281a0dab3a31f55218f63c2ab6586 100644 (file)
@@ -140,7 +140,13 @@ class MangaLel extends BasicSearchable {
                                                        InputStream in = Instance.getInstance().getCache().open(new URL(coverUrl), getSupport(),
                                                                        true);
                                                        try {
-                                                               meta.setCover(new Image(in));
+                                                               Image ii = new Image(in);
+                                                               if (ii.getSize() == 0) {
+                                                                       ii.close();
+                                                                       throw new IOException(
+                                                                                       "Empty image not accepted");
+                                                               }
+                                                               meta.setCover(ii);
                                                        } finally {
                                                                in.close();
                                                        }
index 7768052cafc758094e38c1968f5919f6b853b8bc..f3c30bc9657dfe1a70555d8104cd591ad3bf1523 100644 (file)
@@ -85,7 +85,13 @@ public class BasicSupportHelper {
                        InputStream in = null;
                        try {
                                in = Instance.getInstance().getCache().open(url, support, true);
-                               return new Image(in);
+                               Image img = new Image(in);
+                               if (img.getSize() == 0) {
+                                       img.close();
+                                       throw new IOException(
+                                                       "Empty image not accepted");
+                               }
+                               return img;
                        } catch (IOException e) {
                        } finally {
                                if (in != null) {
index 576cb17e78bb3abfe845a1b053df47618636e5c6..f56b50c2b67a6dd9f5a4b1e0de572767d0a42dde 100644 (file)
@@ -55,7 +55,13 @@ public class BasicSupportImages {
                        InputStream in = null;
                        try {
                                in = Instance.getInstance().getCache().open(url, support, true);
-                               return new Image(in);
+                               Image img = new Image(in);
+                               if (img.getSize() == 0) {
+                                       img.close();
+                                       throw new IOException(
+                                                       "Empty image not accepted");
+                               }
+                               return img;
                        } catch (IOException e) {
                        } finally {
                                if (in != null) {
index a50ee3cf48a962a38b5ebe52b33184c956169ffd..40ff3fc027c7e52beca3426017e1a6a58972fbbe 100644 (file)
@@ -651,7 +651,13 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
                        InputStream in = null;
                        try {
                                in = Instance.getInstance().getCache().open(url, getSupport(url), true);
-                               return new Image(in);
+                               Image img = new Image(in);
+                               if (img.getSize() == 0) {
+                                       img.close();
+                                       throw new IOException(
+                                                       "Empty image not accepted");
+                               }
+                               return img;
                        } catch (IOException e) {
                        } finally {
                                if (in != null) {
index 7fe496d97ea8acb9e8869bb41c37d6723e19a636..a5391d07575e9f6102ab531e4a756c1be718f711 100644 (file)
@@ -97,7 +97,13 @@ class Cbz extends Epub {
                                        if (imageEntry) {
                                                String uuid = meta.getUuid() + "_" + entry.getName();
                                                try {
-                                                       images.put(uuid, new Image(zipIn));
+                                                       Image img = new Image(zipIn);
+                                                       if (img.getSize() == 0) {
+                                                               img.close();
+                                                               throw new IOException(
+                                                                               "Empty image not accepted");
+                                                       }
+                                                       images.put(uuid, img);
                                                } catch (Exception e) {
                                                        Instance.getInstance().getTraceHandler().error(e);
                                                }
index 965a27affda88bfe8919e744b80962f58c3aa465..783d724e36aaa84e822f1fb5f4c6590371a4a8fd 100644 (file)
@@ -128,7 +128,13 @@ class Epub extends InfoText {
                                                // Cover
                                                if (getCover() && cover == null) {
                                                        try {
-                                                               cover = new Image(zipIn);
+                                                               Image img = new Image(zipIn);
+                                                               if (img.getSize() == 0) {
+                                                                       img.close();
+                                                                       throw new IOException(
+                                                                                       "Empty image not accepted");
+                                                               }
+                                                               cover = img;
                                                        } catch (Exception e) {
                                                                Instance.getInstance().getTraceHandler()
                                                                                .error(e);
index 43d01d19494f616c6811e5757da4a6f2e14c83cc..e6dd6118721b93aec36c0d7c734faad1c6d9a95b 100644 (file)
@@ -147,7 +147,13 @@ class FimfictionApi extends BasicSupport {
                        try {
                                InputStream in = Instance.getInstance().getCache().open(coverImageUrl, null, true);
                                try {
-                                       meta.setCover(new Image(in));
+                                       Image img = new Image(in);
+                                       if (img.getSize() == 0) {
+                                               img.close();
+                                               throw new IOException(
+                                                               "Empty image not accepted");
+                                       }
+                                       meta.setCover(img);
                                } finally {
                                        in.close();
                                }
index de0b871331ef313b6be628c382c9487f281b5c3e..5910a371aedf7272e546ec7170b508516879ced1 100644 (file)
@@ -138,11 +138,17 @@ class MangaLel extends BasicSupport {
                        if (img != null) {
                                String coverUrl = img.absUrl("src");
 
-                               InputStream coverIn;
                                try {
-                                       coverIn = Instance.getInstance().getCache().open(new URL(coverUrl), this, true);
+                                       InputStream coverIn = Instance.getInstance().getCache()
+                                                       .open(new URL(coverUrl), this, true);
                                        try {
-                                               return new Image(coverIn);
+                                               Image ii = new Image(coverIn);
+                                               if (ii.getSize() == 0) {
+                                                       ii.close();
+                                                       throw new IOException("Empty image not accepted");
+                                               }
+                                               
+                                               return ii;
                                        } finally {
                                                coverIn.close();
                                        }