From 206895959da049c87cb97f5e0d67d15161ee1f2b Mon Sep 17 00:00:00 2001 From: Maximiliano Curia Date: Thu, 15 Oct 2015 23:44:08 +0200 Subject: [PATCH] Handle null values Avoid segfaults on badly detected files. Currently inputstream returns null on directories, and probably in unreadable files. --- zlibrary/core/src/filesystem/tar/ZLTar.cpp | 1 + zlibrary/core/src/filesystem/zip/ZLZipDir.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/zlibrary/core/src/filesystem/tar/ZLTar.cpp b/zlibrary/core/src/filesystem/tar/ZLTar.cpp index 2b16c5268..627c50477 100644 --- a/zlibrary/core/src/filesystem/tar/ZLTar.cpp +++ b/zlibrary/core/src/filesystem/tar/ZLTar.cpp @@ -193,6 +193,7 @@ size_t ZLTarInputStream::sizeOfOpened() { void ZLTarDir::collectFiles(std::vector &names, bool) { shared_ptr stream = ZLFile(path()).inputStream(); + if (stream == 0) return; const ZLTarHeaderCache &cache = ZLTarHeaderCache::cache(*stream); cache.collectFileNames(names); } diff --git a/zlibrary/core/src/filesystem/zip/ZLZipDir.cpp b/zlibrary/core/src/filesystem/zip/ZLZipDir.cpp index 671ac7cf6..de0d0e6b2 100644 --- a/zlibrary/core/src/filesystem/zip/ZLZipDir.cpp +++ b/zlibrary/core/src/filesystem/zip/ZLZipDir.cpp @@ -23,6 +23,7 @@ void ZLZipDir::collectFiles(std::vector &names, bool) { shared_ptr stream = ZLFile(path()).inputStream(); + if (stream == 0) return; const ZLZipEntryCache &cache = ZLZipEntryCache::cache(*stream); cache.collectFileNames(names); }