From 3fd1bc2df7191d5e6f82a6e5f1c473f813b92099 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 4 May 2025 13:12:46 +0530 Subject: [PATCH] E-book viewer: Fix some links not being processed correctly for very large EPUB files with many internal HTML files. --- src/calibre/ebooks/oeb/polish/container.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index cf81c688a3..6db4191e2f 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -548,10 +548,16 @@ class Container(ContainerBase): # {{{ return name and name in self.name_path_map def has_name_and_is_not_empty(self, name): - if not self.has_name(name): + path = self.name_path_map.get(name) + if not path: return False try: - return os.path.getsize(self.name_path_map[name]) > 0 + if (sz := os.path.getsize(path)) == 0: + # this can happen when the directory entry is not flushed (which happens during fast EPUB extraction), so + # open the file and check to be sure. + with open(path) as f: + sz = f.seek(0, os.SEEK_END) + return sz > 0 except OSError: return False