summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/quazip/zip.c
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/quazip/zip.c')
-rw-r--r--rbutil/rbutilqt/quazip/zip.c46
1 files changed, 27 insertions, 19 deletions
diff --git a/rbutil/rbutilqt/quazip/zip.c b/rbutil/rbutilqt/quazip/zip.c
index 96496539f4..0f3deb04c1 100644
--- a/rbutil/rbutilqt/quazip/zip.c
+++ b/rbutil/rbutilqt/quazip/zip.c
@@ -12,6 +12,9 @@
Modifications for QIODevice support and other QuaZIP fixes
Copyright (C) 2005-2014 Sergey A. Tachenov
+ Fixing static code analysis issues
+ Copyright (C) 2016 Intel Deutschland GmbH
+
Changes
Oct-2009 - Mathias Svensson - Remove old C style function prototypes
Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives
@@ -29,7 +32,8 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
-#include "zlib.h"
+
+#include <zlib.h>
#if (ZLIB_VERNUM < 0x1270)
typedef uLongf z_crc_t;
#endif
@@ -192,7 +196,7 @@ typedef struct
#ifndef NOCRYPT
#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
-#include "crypt.h"
+#include "minizip_crypt.h"
#endif
local linkedlist_datablock_internal* allocate_new_datablock()
@@ -527,13 +531,14 @@ local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_f
if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
break;
- for (i=(int)uReadSize-3; (i--)>0;)
+ for (i=(int)uReadSize-3; (i--)>0;){
if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
{
uPosFound = uReadPos+i;
break;
}
+ }
if (uPosFound!=0)
break;
@@ -988,7 +993,9 @@ int Write_LocalFileHeader(zip64_internal* zi, const char* filename,
if (err==ZIP_OK)
{
- if(zi->ci.zip64)
+ if(zi->ci.flag & ZIP_ENCODING_UTF8)
+ err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)63,2);/* Version 6.3 is required for Unicode support */
+ else if(zi->ci.zip64)
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */
else
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)version_to_extract,2);
@@ -1146,6 +1153,8 @@ extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename,
}
zi->ci.flag = flagBase;
+ if (zi->flags & ZIP_ENCODING_UTF8)
+ zi->ci.flag |= ZIP_ENCODING_UTF8;
if ((level==8) || (level==9))
zi->ci.flag |= 2;
if (level==2)
@@ -1171,6 +1180,9 @@ extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename,
zi->ci.size_centralExtraFree = 32; /* Extra space we have reserved in case we need to add ZIP64 extra info data */
zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree);
+ if(!zi->ci.central_header) {
+ return (Z_MEM_ERROR);
+ }
zi->ci.size_centralExtra = size_extrafield_global;
zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
@@ -1509,15 +1521,9 @@ extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned in
if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
{
- uLong uTotalOutBefore = zi->ci.stream.total_out;
+ uInt uAvailOutBefore = zi->ci.stream.avail_out;
err=deflate(&zi->ci.stream, Z_NO_FLUSH);
- if(uTotalOutBefore > zi->ci.stream.total_out)
- {
- int bBreak = 0;
- bBreak++;
- }
-
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
+ zi->ci.pos_in_buffered_data += uAvailOutBefore - zi->ci.stream.avail_out;
}
else
{
@@ -1571,7 +1577,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_s
{
while (err==ZIP_OK)
{
- uLong uTotalOutBefore;
+ uLong uAvailOutBefore;
if (zi->ci.stream.avail_out == 0)
{
if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
@@ -1579,9 +1585,9 @@ extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_s
zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
zi->ci.stream.next_out = zi->ci.buffered_data;
}
- uTotalOutBefore = zi->ci.stream.total_out;
+ uAvailOutBefore = zi->ci.stream.avail_out;
err=deflate(&zi->ci.stream, Z_FINISH);
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
+ zi->ci.pos_in_buffered_data += uAvailOutBefore - zi->ci.stream.avail_out;
}
}
else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
@@ -1654,8 +1660,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_s
/*version Made by*/
zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2);
/*version needed*/
- zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2);
-
+ zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)((zi->ci.flag & ZIP_ENCODING_UTF8) ? 63 : 45),2);
}
zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/
@@ -1737,7 +1742,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_s
if (err==ZIP_OK)
err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader);
- free(zi->ci.central_header);
+ TRYFREE(zi->ci.central_header);
if (err==ZIP_OK)
{
@@ -1849,7 +1854,7 @@ int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centra
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
if (err==ZIP_OK) /* version needed */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
+ err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)((zi->ci.flag & ZIP_ENCODING_UTF8) ? 63 : 45),2);
if (err==ZIP_OK) /* number of this disk */
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
@@ -2031,6 +2036,9 @@ extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHe
return ZIP_PARAMERROR;
pNewHeader = (char*)ALLOC(*dataLen);
+ if(!pNewHeader) {
+ return Z_MEM_ERROR;
+ }
pTmp = pNewHeader;
while(p < (pData + *dataLen))