From 55650f364cdf9d0b0ff36479dba0e599004e10ca Mon Sep 17 00:00:00 2001 From: Littleboy Date: Sun, 24 Apr 2011 23:53:24 -0400 Subject: COMMON: Add proper error handling to the ZipArchive class - Add check in listMembers and skip files that can't be enumerated. - Add checks for all function calls in createReadStreamForMember (and no longer return a stream from an uninitialized buffer when the file cannot be read). --- common/unzip.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'common/unzip.cpp') diff --git a/common/unzip.cpp b/common/unzip.cpp index cd5d37f4bd..7b78da0faf 100644 --- a/common/unzip.cpp +++ b/common/unzip.cpp @@ -1470,11 +1470,13 @@ int ZipArchive::listMembers(Common::ArchiveMemberList &list) { while (err == UNZ_OK) { char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; - unzGetCurrentFileInfo(_zipFile, NULL, - szCurrentFileName, sizeof(szCurrentFileName)-1, - NULL, 0, NULL, 0); - list.push_back(ArchiveMemberList::value_type(new GenericArchiveMember(szCurrentFileName, this))); - matches++; + if (unzGetCurrentFileInfo(_zipFile, NULL, + szCurrentFileName, sizeof(szCurrentFileName)-1, + NULL, 0, NULL, 0) == UNZ_OK) { + list.push_back(ArchiveMemberList::value_type(new GenericArchiveMember(szCurrentFileName, this))); + matches++; + } + err = unzGoToNextFile(_zipFile); } @@ -1493,18 +1495,31 @@ Common::SeekableReadStream *ZipArchive::createReadStreamForMember(const Common:: return 0; unz_file_info fileInfo; - unzOpenCurrentFile(_zipFile); - unzGetCurrentFileInfo(_zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0); + if (unzOpenCurrentFile(_zipFile) != UNZ_OK) + return 0; + + if (unzGetCurrentFileInfo(_zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0) != UNZ_OK) + return 0; + byte *buffer = (byte *)malloc(fileInfo.uncompressed_size); assert(buffer); - unzReadCurrentFile(_zipFile, buffer, fileInfo.uncompressed_size); - unzCloseCurrentFile(_zipFile); + + if (unzReadCurrentFile(_zipFile, buffer, fileInfo.uncompressed_size) != (int)fileInfo.uncompressed_size) { + free(buffer); + return 0; + } + + if (unzCloseCurrentFile(_zipFile) != UNZ_OK) { + free(buffer); + return 0; + } + return new Common::MemoryReadStream(buffer, fileInfo.uncompressed_size, DisposeAfterUse::YES); // FIXME: instead of reading all into a memory stream, we could // instead create a new ZipStream class. But then we have to be // careful to handle the case where the client code opens multiple - // files in the archive and tries to use them indepenendtly. + // files in the archive and tries to use them independently. } Archive *makeZipArchive(const String &name) { -- cgit v1.2.3 From 9414d7a6e287ff8abfb5746b564e92c8f0e6de58 Mon Sep 17 00:00:00 2001 From: Ori Avtalion Date: Sun, 24 Apr 2011 11:34:27 +0300 Subject: JANITORIAL: Reduce header dependencies in shared code Some backends may break as I only compiled SDL --- common/unzip.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'common/unzip.cpp') diff --git a/common/unzip.cpp b/common/unzip.cpp index 7b78da0faf..a55dfd1cad 100644 --- a/common/unzip.cpp +++ b/common/unzip.cpp @@ -105,7 +105,6 @@ typedef struct { #include "common/fs.h" #include "common/unzip.h" -#include "common/file.h" #include "common/memstream.h" #include "common/hashmap.h" -- cgit v1.2.3 From c0bd496c909629067edb44893e4a819bd705aeed Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 2 May 2011 17:19:35 +0200 Subject: COMMON: Fix compilation when zlib support is enabled. --- common/unzip.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'common/unzip.cpp') diff --git a/common/unzip.cpp b/common/unzip.cpp index a55dfd1cad..d56893f3cd 100644 --- a/common/unzip.cpp +++ b/common/unzip.cpp @@ -68,6 +68,8 @@ PkWare has also a specification at : ftp://ftp.pkware.com/probdesc.zip */ +// Disable symbol overrides so that we can use zlib.h +#define FORBIDDEN_SYMBOL_ALLOW_ALL #include "common/scummsys.h" -- cgit v1.2.3