do not allow empty cover images
[fanfix.git] / src / be / nikiroo / fanfix / searchable / Fanfiction.java
index c2dfd5d5714a8f4c5e388aeccf7a8cd51053f303..cbc927bcc2d981b028311be59fa2d1ba7c152542 100644 (file)
@@ -285,19 +285,22 @@ class Fanfiction extends BasicSearchable {
                                        String coverUrl = cover.absUrl("src");
 
                                        try {
-                                               InputStream in = Instance.getCache().open(
-                                                               new URL(coverUrl), getSupport(), true);
+                                               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();
                                                }
                                        } catch (Exception e) {
                                                // Should not happen on Fanfiction.net
-                                               Instance.getTraceHandler().error(
-                                                               new Exception(
-                                                                               "Cannot download cover for Fanfiction story in search mode: "
-                                                                                               + meta.getTitle(), e));
+                                               Instance.getInstance().getTraceHandler().error(new Exception(
+                                                               "Cannot download cover for Fanfiction story in search mode: " + meta.getTitle(), e));
                                        }
                                }
                        }
@@ -337,8 +340,7 @@ class Fanfiction extends BasicSearchable {
                                }
 
                                meta.setResume(getSupport().makeChapter(new URL(sourceUrl), 0,
-                                               Instance.getTrans().getString(StringId.DESCRIPTION),
-                                               resume));
+                                               Instance.getInstance().getTrans().getString(StringId.DESCRIPTION), resume));
                        }
 
                        // How are the tags ordered?