From: Niki Roo Date: Fri, 15 May 2020 11:00:21 +0000 (+0200) Subject: do not allow empty cover images X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=0a264fbe3d5a43516006052574a5f322d9d38897;p=fanfix.git do not allow empty cover images --- diff --git a/src/be/nikiroo/fanfix/library/LocalLibrary.java b/src/be/nikiroo/fanfix/library/LocalLibrary.java index 7220a39..f655d4d 100644 --- a/src/be/nikiroo/fanfix/library/LocalLibrary.java +++ b/src/be/nikiroo/fanfix/library/LocalLibrary.java @@ -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(); diff --git a/src/be/nikiroo/fanfix/library/WebLibrary.java b/src/be/nikiroo/fanfix/library/WebLibrary.java index 0f2510d..9af38e2 100644 --- a/src/be/nikiroo/fanfix/library/WebLibrary.java +++ b/src/be/nikiroo/fanfix/library/WebLibrary.java @@ -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; } diff --git a/src/be/nikiroo/fanfix/searchable/Fanfiction.java b/src/be/nikiroo/fanfix/searchable/Fanfiction.java index e2fba1f..cbc927b 100644 --- a/src/be/nikiroo/fanfix/searchable/Fanfiction.java +++ b/src/be/nikiroo/fanfix/searchable/Fanfiction.java @@ -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(); } diff --git a/src/be/nikiroo/fanfix/searchable/MangaLel.java b/src/be/nikiroo/fanfix/searchable/MangaLel.java index 5ba21a0..354edb4 100644 --- a/src/be/nikiroo/fanfix/searchable/MangaLel.java +++ b/src/be/nikiroo/fanfix/searchable/MangaLel.java @@ -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(); } diff --git a/src/be/nikiroo/fanfix/supported/BasicSupportHelper.java b/src/be/nikiroo/fanfix/supported/BasicSupportHelper.java index 7768052..f3c30bc 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupportHelper.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupportHelper.java @@ -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) { diff --git a/src/be/nikiroo/fanfix/supported/BasicSupportImages.java b/src/be/nikiroo/fanfix/supported/BasicSupportImages.java index 576cb17..f56b50c 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupportImages.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupportImages.java @@ -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) { diff --git a/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java b/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java index a50ee3c..40ff3fc 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java @@ -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) { diff --git a/src/be/nikiroo/fanfix/supported/Cbz.java b/src/be/nikiroo/fanfix/supported/Cbz.java index 7fe496d..a5391d0 100644 --- a/src/be/nikiroo/fanfix/supported/Cbz.java +++ b/src/be/nikiroo/fanfix/supported/Cbz.java @@ -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); } diff --git a/src/be/nikiroo/fanfix/supported/Epub.java b/src/be/nikiroo/fanfix/supported/Epub.java index 965a27a..783d724 100644 --- a/src/be/nikiroo/fanfix/supported/Epub.java +++ b/src/be/nikiroo/fanfix/supported/Epub.java @@ -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); diff --git a/src/be/nikiroo/fanfix/supported/FimfictionApi.java b/src/be/nikiroo/fanfix/supported/FimfictionApi.java index 43d01d1..e6dd611 100644 --- a/src/be/nikiroo/fanfix/supported/FimfictionApi.java +++ b/src/be/nikiroo/fanfix/supported/FimfictionApi.java @@ -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(); } diff --git a/src/be/nikiroo/fanfix/supported/MangaLel.java b/src/be/nikiroo/fanfix/supported/MangaLel.java index de0b871..5910a37 100644 --- a/src/be/nikiroo/fanfix/supported/MangaLel.java +++ b/src/be/nikiroo/fanfix/supported/MangaLel.java @@ -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(); }