From 4b31842c4a708c3c9bd5fa847ba25d11a0e29496 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 12 Nov 2018 12:16:05 +0100 Subject: [PATCH] Correctly convert filesize from Kbyte to byte. `reader.getFileSize()` return the size of the zim in Kbyte in a `unsigned int` (32 bits). This is ok as it would overflow if the size of the size is greater than 4294967295 kbytes (so ~4Tbytes). However, we need to convert the return size into a unsigned 64 bits integer else, when converting to bytes, we will overflow at 4Gbytes. Even in `m_size` is a uint64_t. --- src/book.cpp | 2 +- src/reader.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/book.cpp b/src/book.cpp index 6a173ba9c..6d41a87eb 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -87,7 +87,7 @@ void Book::update(const kiwix::Reader& reader) m_origId = reader.getOrigId(); m_articleCount = reader.getArticleCount(); m_mediaCount = reader.getMediaCount(); - m_size = reader.getFileSize() << 10; + m_size = static_cast(reader.getFileSize()) << 10; reader.getFavicon(m_favicon, m_faviconMimeType); } diff --git a/src/reader.cpp b/src/reader.cpp index 00ac9a48e..abe704de6 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -851,7 +851,7 @@ bool Reader::isCorrupted() const unsigned int Reader::getFileSize() const { zim::File* file = this->getZimFileHandler(); - zim::offset_type size = 0; + zim::size_type size = 0; if (file != NULL) { size = file->getFilesize();