2003-03-14 21:59:51 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-03-09 05:13:56 +03:00
|
|
|
|
2002-10-31 09:27:20 +03:00
|
|
|
/*
|
1999-03-09 05:13:56 +03:00
|
|
|
* This module implements a simple archive extractor for the PKZIP format.
|
1999-05-19 07:21:03 +04:00
|
|
|
*
|
|
|
|
* The underlying nsZipArchive is NOT thread-safe. Do not pass references
|
|
|
|
* or pointers to it across thread boundaries.
|
1999-03-09 05:13:56 +03:00
|
|
|
*/
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
#define READTYPE int32_t
|
1999-09-08 02:03:53 +04:00
|
|
|
#include "zlib.h"
|
Bug 1355661 - Add support for brotli streams in Jar archives. r=aklotz
Modern compression algorithms are better than zlib both in terms of
space and time. The jar format, used for e.g. omni.ja, addons, etc.
could benefit from using such modern algorithms, but the format only
allows a limited set of compression algorithms.
However, the format in itself is flexible, in that it can be extended
with arbitrary compression algorithms. This breaks compatibility with
programs like unzip, obviously, but we've never promised the files
shipped with Firefox will always remain "valid" zips (which they already
aren't, but they currently work with most zip readers).
With this change, we allow those archives to contain brotli streams,
using an arbitrary large value for the compression type in the Zip local
file header. This only allows to read such archives, but not to produce
them, and, for now, support for brotli streams is kept Nightly-only,
until everything is pieced together and we're happy to ship it.
--HG--
extra : rebase_source : fa637251f460ad0d91d5f5bec392c6e59555e80d
2017-04-07 08:48:25 +03:00
|
|
|
#ifdef MOZ_JAR_BROTLI
|
2017-08-09 13:45:39 +03:00
|
|
|
# include "brotli/decode.h" // brotli
|
Bug 1355661 - Add support for brotli streams in Jar archives. r=aklotz
Modern compression algorithms are better than zlib both in terms of
space and time. The jar format, used for e.g. omni.ja, addons, etc.
could benefit from using such modern algorithms, but the format only
allows a limited set of compression algorithms.
However, the format in itself is flexible, in that it can be extended
with arbitrary compression algorithms. This breaks compatibility with
programs like unzip, obviously, but we've never promised the files
shipped with Firefox will always remain "valid" zips (which they already
aren't, but they currently work with most zip readers).
With this change, we allow those archives to contain brotli streams,
using an arbitrary large value for the compression type in the Zip local
file header. This only allows to read such archives, but not to produce
them, and, for now, support for brotli streams is kept Nightly-only,
until everything is pieced together and we're happy to ship it.
--HG--
extra : rebase_source : fa637251f460ad0d91d5f5bec392c6e59555e80d
2017-04-07 08:48:25 +03:00
|
|
|
#endif
|
1999-11-16 04:52:29 +03:00
|
|
|
#include "nsISupportsUtils.h"
|
2009-08-13 00:50:12 +04:00
|
|
|
#include "prio.h"
|
|
|
|
#include "plstr.h"
|
2018-03-02 04:11:39 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2019-04-13 21:46:04 +03:00
|
|
|
#include "mozilla/MemUtils.h"
|
2015-11-04 00:36:32 +03:00
|
|
|
#include "mozilla/UniquePtrExtensions.h"
|
2009-08-13 00:50:12 +04:00
|
|
|
#include "stdlib.h"
|
2019-03-07 23:46:52 +03:00
|
|
|
#include "nsDirectoryService.h"
|
2009-08-13 00:50:12 +04:00
|
|
|
#include "nsWildCard.h"
|
2019-02-26 02:40:55 +03:00
|
|
|
#include "nsXULAppAPI.h"
|
2009-08-13 00:50:12 +04:00
|
|
|
#include "nsZipArchive.h"
|
2010-08-18 21:34:07 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "prenv.h"
|
2010-11-11 23:13:48 +03:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
2011-06-03 00:59:04 +04:00
|
|
|
|
2002-03-11 23:18:35 +03:00
|
|
|
// For placement new used for arena allocations of zip file list
|
2013-07-12 04:16:41 +04:00
|
|
|
#include <new>
|
2006-05-02 23:33:09 +04:00
|
|
|
#define ZIP_ARENABLOCKSIZE (1 * 1024)
|
2002-03-11 23:18:35 +03:00
|
|
|
|
1999-11-03 02:46:09 +03:00
|
|
|
#ifdef XP_UNIX
|
2013-03-21 13:28:13 +04:00
|
|
|
# include <sys/mman.h>
|
2004-08-17 04:12:04 +04:00
|
|
|
# include <sys/types.h>
|
1999-11-02 23:37:28 +03:00
|
|
|
# include <sys/stat.h>
|
2001-09-21 03:33:23 +04:00
|
|
|
# include <limits.h>
|
|
|
|
# include <unistd.h>
|
2014-02-11 02:57:01 +04:00
|
|
|
#elif defined(XP_WIN)
|
1999-11-02 23:37:28 +03:00
|
|
|
# include <io.h>
|
|
|
|
#endif
|
1999-03-09 05:13:56 +03:00
|
|
|
|
2009-06-26 09:43:15 +04:00
|
|
|
#ifdef __SYMBIAN32__
|
|
|
|
# include <sys/syslimits.h>
|
|
|
|
#endif /*__SYMBIAN32__*/
|
|
|
|
|
2006-03-30 02:10:37 +04:00
|
|
|
#ifndef XP_UNIX /* we need some constants defined in limits.h and unistd.h */
|
2001-09-21 03:33:23 +04:00
|
|
|
# ifndef S_IFMT
|
|
|
|
# define S_IFMT 0170000
|
|
|
|
# endif
|
|
|
|
# ifndef S_IFLNK
|
|
|
|
# define S_IFLNK 0120000
|
|
|
|
# endif
|
|
|
|
# ifndef PATH_MAX
|
|
|
|
# define PATH_MAX 1024
|
|
|
|
# endif
|
|
|
|
#endif /* XP_UNIX */
|
|
|
|
|
2013-02-19 14:02:12 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
# include "private/pprio.h" // To get PR_ImportFile
|
|
|
|
#endif
|
2009-10-17 19:54:54 +04:00
|
|
|
|
2010-08-18 21:34:07 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static const uint32_t kMaxNameLength = PATH_MAX; /* Maximum name length */
|
2009-10-17 19:54:54 +04:00
|
|
|
// For synthetic zip entries. Date/time corresponds to 1980-01-01 00:00.
|
2012-08-22 19:56:38 +04:00
|
|
|
static const uint16_t kSyntheticTime = 0;
|
|
|
|
static const uint16_t kSyntheticDate = (1 + (1 << 5) + (0 << 9));
|
2009-10-17 19:54:54 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint16_t xtoint(const uint8_t *ii);
|
|
|
|
static uint32_t xtolong(const uint8_t *ll);
|
|
|
|
static uint32_t HashName(const char *aName, uint16_t nameLen);
|
1999-03-09 05:13:56 +03:00
|
|
|
|
2013-02-19 14:02:12 +04:00
|
|
|
class ZipArchiveLogger {
|
|
|
|
public:
|
2019-03-08 01:54:53 +03:00
|
|
|
void Init(const char *env) {
|
2013-02-19 14:02:12 +04:00
|
|
|
if (!fd) {
|
|
|
|
nsCOMPtr<nsIFile> logFile;
|
|
|
|
nsresult rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(env), false,
|
|
|
|
getter_AddRefs(logFile));
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
|
|
|
// Create the log file and its parent directory (in case it doesn't exist)
|
2016-08-18 06:30:12 +03:00
|
|
|
rv = logFile->Create(nsIFile::NORMAL_FILE_TYPE, 0644);
|
|
|
|
if (NS_FAILED(rv)) return;
|
2013-02-19 14:02:12 +04:00
|
|
|
|
|
|
|
PRFileDesc *file;
|
|
|
|
#ifdef XP_WIN
|
|
|
|
// PR_APPEND is racy on Windows, so open a handle ourselves with flags
|
|
|
|
// that will work, and use PR_ImportFile to make it a PRFileDesc. This can
|
|
|
|
// go away when bug 840435 is fixed.
|
|
|
|
nsAutoString path;
|
|
|
|
logFile->GetPath(path);
|
|
|
|
if (path.IsEmpty()) return;
|
|
|
|
HANDLE handle =
|
|
|
|
CreateFileW(path.get(), FILE_APPEND_DATA, FILE_SHARE_WRITE, nullptr,
|
2013-10-24 00:36:26 +04:00
|
|
|
OPEN_ALWAYS, 0, nullptr);
|
2013-02-19 14:02:12 +04:00
|
|
|
if (handle == INVALID_HANDLE_VALUE) return;
|
|
|
|
file = PR_ImportFile((PROsfd)handle);
|
|
|
|
if (!file) return;
|
|
|
|
#else
|
|
|
|
rv = logFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_APPEND,
|
|
|
|
0644, &file);
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
#endif
|
|
|
|
fd = file;
|
|
|
|
}
|
2019-03-08 01:54:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Write(const nsACString &zip, const char *entry) const {
|
|
|
|
if (fd) {
|
|
|
|
nsCString buf(zip);
|
|
|
|
buf.Append(' ');
|
|
|
|
buf.Append(entry);
|
|
|
|
buf.Append('\n');
|
|
|
|
PR_Write(fd, buf.get(), buf.Length());
|
|
|
|
}
|
2013-02-19 14:02:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddRef() {
|
|
|
|
MOZ_ASSERT(refCnt >= 0);
|
|
|
|
++refCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Release() {
|
|
|
|
MOZ_ASSERT(refCnt > 0);
|
|
|
|
if ((0 == --refCnt) && fd) {
|
|
|
|
PR_Close(fd);
|
2013-10-24 00:36:26 +04:00
|
|
|
fd = nullptr;
|
2013-02-19 14:02:12 +04:00
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-02-19 14:02:12 +04:00
|
|
|
private:
|
|
|
|
int refCnt;
|
2019-03-08 01:54:53 +03:00
|
|
|
PRFileDesc *fd;
|
2013-02-19 14:02:12 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static ZipArchiveLogger zipLog;
|
|
|
|
|
2001-12-15 09:31:49 +03:00
|
|
|
//***********************************************************
|
2009-10-09 16:30:45 +04:00
|
|
|
// For every inflation the following allocations are done:
|
2012-01-12 03:20:56 +04:00
|
|
|
// malloc(1 * 9520)
|
|
|
|
// malloc(32768 * 1)
|
2001-12-15 09:31:49 +03:00
|
|
|
//***********************************************************
|
|
|
|
|
2006-05-02 23:33:09 +04:00
|
|
|
nsresult gZlibInit(z_stream *zs) {
|
|
|
|
memset(zs, 0, sizeof(z_stream));
|
|
|
|
int zerr = inflateInit2(zs, -MAX_WBITS);
|
2009-10-08 18:24:22 +04:00
|
|
|
if (zerr != Z_OK) return NS_ERROR_OUT_OF_MEMORY;
|
2003-03-14 21:59:51 +03:00
|
|
|
|
2009-10-08 18:24:22 +04:00
|
|
|
return NS_OK;
|
2003-03-14 21:59:51 +03:00
|
|
|
}
|
|
|
|
|
2009-08-13 00:50:12 +04:00
|
|
|
nsZipHandle::nsZipHandle()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mFileData(nullptr),
|
2009-08-13 00:50:12 +04:00
|
|
|
mLen(0),
|
2012-07-30 18:20:58 +04:00
|
|
|
mMap(nullptr),
|
2009-08-13 00:50:12 +04:00
|
|
|
mRefCnt(0),
|
2016-04-07 04:28:24 +03:00
|
|
|
mFileStart(nullptr),
|
|
|
|
mTotalLen(0) {}
|
2009-08-13 00:50:12 +04:00
|
|
|
|
2013-07-19 06:23:44 +04:00
|
|
|
NS_IMPL_ADDREF(nsZipHandle)
|
|
|
|
NS_IMPL_RELEASE(nsZipHandle)
|
2009-08-13 00:50:12 +04:00
|
|
|
|
2015-07-30 11:05:57 +03:00
|
|
|
nsresult nsZipHandle::Init(nsIFile *file, nsZipHandle **ret, PRFileDesc **aFd) {
|
2010-09-09 07:37:34 +04:00
|
|
|
mozilla::AutoFDClose fd;
|
2013-03-21 13:28:13 +04:00
|
|
|
int32_t flags = PR_RDONLY;
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
flags |= nsIFile::OS_READAHEAD;
|
|
|
|
#endif
|
|
|
|
nsresult rv = file->OpenNSPRFileDesc(flags, 0000, &fd.rwget());
|
2010-09-09 07:37:34 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t size = PR_Available64(fd);
|
2009-08-13 00:50:12 +04:00
|
|
|
if (size >= INT32_MAX) return NS_ERROR_FILE_TOO_BIG;
|
|
|
|
|
|
|
|
PRFileMap *map = PR_CreateFileMap(fd, size, PR_PROT_READONLY);
|
|
|
|
if (!map) return NS_ERROR_FAILURE;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t *buf = (uint8_t *)PR_MemMap(map, 0, (uint32_t)size);
|
2009-11-07 18:19:20 +03:00
|
|
|
// Bug 525755: PR_MemMap fails when fd points at something other than a normal
|
|
|
|
// file.
|
|
|
|
if (!buf) {
|
|
|
|
PR_CloseFileMap(map);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-08-13 00:50:12 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsZipHandle> handle = new nsZipHandle();
|
2009-10-04 21:20:45 +04:00
|
|
|
if (!handle) {
|
2012-08-22 19:56:38 +04:00
|
|
|
PR_MemUnmap(buf, (uint32_t)size);
|
2009-10-04 21:20:45 +04:00
|
|
|
PR_CloseFileMap(map);
|
2009-08-13 00:50:12 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2009-10-04 21:20:45 +04:00
|
|
|
}
|
2009-08-13 00:50:12 +04:00
|
|
|
|
2013-03-21 13:28:13 +04:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
if (aFd) {
|
|
|
|
*aFd = fd.forget();
|
|
|
|
}
|
2014-07-18 06:46:24 +04:00
|
|
|
#else
|
2015-07-30 11:05:57 +03:00
|
|
|
handle->mNSPRFileDesc = fd.forget();
|
2013-03-21 13:28:13 +04:00
|
|
|
#endif
|
2009-08-13 00:50:12 +04:00
|
|
|
handle->mMap = map;
|
2011-12-08 14:03:36 +04:00
|
|
|
handle->mFile.Init(file);
|
2016-04-07 04:28:24 +03:00
|
|
|
handle->mTotalLen = (uint32_t)size;
|
|
|
|
handle->mFileStart = buf;
|
2016-05-04 22:57:21 +03:00
|
|
|
rv = handle->findDataStart();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
PR_MemUnmap(buf, (uint32_t)size);
|
|
|
|
PR_CloseFileMap(map);
|
|
|
|
return rv;
|
|
|
|
}
|
2014-03-15 23:00:15 +04:00
|
|
|
handle.forget(ret);
|
2010-09-09 07:37:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsZipHandle::Init(nsZipArchive *zip, const char *entry,
|
|
|
|
nsZipHandle **ret) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsZipHandle> handle = new nsZipHandle();
|
2010-09-09 07:37:34 +04:00
|
|
|
if (!handle) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
handle->mBuf = new nsZipItemPtr<uint8_t>(zip, entry);
|
2010-09-09 07:37:34 +04:00
|
|
|
if (!handle->mBuf) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2010-09-20 23:58:40 +04:00
|
|
|
if (!handle->mBuf->Buffer()) return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
handle->mMap = nullptr;
|
2011-12-08 14:03:36 +04:00
|
|
|
handle->mFile.Init(zip, entry);
|
2016-04-07 04:28:24 +03:00
|
|
|
handle->mTotalLen = handle->mBuf->Length();
|
|
|
|
handle->mFileStart = handle->mBuf->Buffer();
|
2016-05-04 22:57:21 +03:00
|
|
|
nsresult rv = handle->findDataStart();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-03-15 23:00:15 +04:00
|
|
|
handle.forget(ret);
|
2009-08-13 00:50:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-11 03:00:01 +03:00
|
|
|
nsresult nsZipHandle::Init(const uint8_t *aData, uint32_t aLen,
|
|
|
|
nsZipHandle **aRet) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsZipHandle> handle = new nsZipHandle();
|
2015-03-11 03:00:01 +03:00
|
|
|
|
2016-04-07 04:28:24 +03:00
|
|
|
handle->mFileStart = aData;
|
|
|
|
handle->mTotalLen = aLen;
|
2016-05-04 22:57:21 +03:00
|
|
|
nsresult rv = handle->findDataStart();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2015-03-11 03:00:01 +03:00
|
|
|
handle.forget(aRet);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-07 04:28:24 +03:00
|
|
|
// This function finds the start of the ZIP data. If the file is a regular ZIP,
|
|
|
|
// this is just the start of the file. If the file is a CRX file, the start of
|
|
|
|
// the data is after the CRX header.
|
|
|
|
// CRX header reference: (CRX version 2)
|
|
|
|
// Header requires little-endian byte ordering with 4-byte alignment.
|
|
|
|
// 32 bits : magicNumber - Defined as a |char m[] = "Cr24"|.
|
|
|
|
// Equivilant to |uint32_t m = 0x34327243|.
|
|
|
|
// 32 bits : version - Unsigned integer representing the CRX file
|
|
|
|
// format version. Currently equal to 2.
|
|
|
|
// 32 bits : pubKeyLength - Unsigned integer representing the length
|
|
|
|
// of the public key in bytes.
|
|
|
|
// 32 bits : sigLength - Unsigned integer representing the length
|
|
|
|
// of the signature in bytes.
|
|
|
|
// pubKeyLength : publicKey - Contents of the author's public key.
|
|
|
|
// sigLength : signature - Signature of the ZIP content.
|
|
|
|
// Signature is created using the RSA
|
2017-06-07 03:50:25 +03:00
|
|
|
// algorithm with the SHA-1 hash function.
|
2016-05-04 22:57:21 +03:00
|
|
|
nsresult nsZipHandle::findDataStart() {
|
2016-04-07 04:28:24 +03:00
|
|
|
// In the CRX header, integers are 32 bits. Our pointer to the file is of
|
|
|
|
// type |uint8_t|, which is guaranteed to be 8 bits.
|
|
|
|
const uint32_t CRXIntSize = 4;
|
|
|
|
|
2016-05-04 22:57:21 +03:00
|
|
|
MOZ_WIN_MEM_TRY_BEGIN
|
2016-04-07 04:28:24 +03:00
|
|
|
if (mTotalLen > CRXIntSize * 4 && xtolong(mFileStart) == kCRXMagic) {
|
|
|
|
const uint8_t *headerData = mFileStart;
|
|
|
|
headerData += CRXIntSize * 2; // Skip magic number and version number
|
|
|
|
uint32_t pubKeyLength = xtolong(headerData);
|
|
|
|
headerData += CRXIntSize;
|
|
|
|
uint32_t sigLength = xtolong(headerData);
|
|
|
|
uint32_t headerSize = CRXIntSize * 4 + pubKeyLength + sigLength;
|
|
|
|
if (mTotalLen > headerSize) {
|
|
|
|
mLen = mTotalLen - headerSize;
|
|
|
|
mFileData = mFileStart + headerSize;
|
2016-05-04 22:57:21 +03:00
|
|
|
return NS_OK;
|
2016-04-07 04:28:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mLen = mTotalLen;
|
|
|
|
mFileData = mFileStart;
|
2016-05-04 22:57:21 +03:00
|
|
|
MOZ_WIN_MEM_TRY_CATCH(return NS_ERROR_FAILURE)
|
|
|
|
return NS_OK;
|
2016-04-07 04:28:24 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t nsZipHandle::SizeOfMapping() { return mTotalLen; }
|
2011-10-25 04:50:47 +04:00
|
|
|
|
2014-07-18 06:46:24 +04:00
|
|
|
nsresult nsZipHandle::GetNSPRFileDesc(PRFileDesc **aNSPRFileDesc) {
|
|
|
|
if (!aNSPRFileDesc) {
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aNSPRFileDesc = mNSPRFileDesc;
|
2015-07-30 11:05:57 +03:00
|
|
|
if (!mNSPRFileDesc) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2014-07-18 06:46:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-13 00:50:12 +04:00
|
|
|
nsZipHandle::~nsZipHandle() {
|
2010-09-09 07:37:34 +04:00
|
|
|
if (mMap) {
|
2016-04-07 04:28:24 +03:00
|
|
|
PR_MemUnmap((void *)mFileStart, mTotalLen);
|
2009-08-13 00:50:12 +04:00
|
|
|
PR_CloseFileMap(mMap);
|
2009-10-04 21:20:45 +04:00
|
|
|
}
|
2016-04-07 04:28:24 +03:00
|
|
|
mFileStart = nullptr;
|
2012-07-30 18:20:58 +04:00
|
|
|
mFileData = nullptr;
|
|
|
|
mMap = nullptr;
|
|
|
|
mBuf = nullptr;
|
2009-08-13 00:50:12 +04:00
|
|
|
}
|
|
|
|
|
1999-03-09 05:13:56 +03:00
|
|
|
//***********************************************************
|
|
|
|
// nsZipArchive -- public methods
|
|
|
|
//***********************************************************
|
|
|
|
|
|
|
|
//---------------------------------------------
|
|
|
|
// nsZipArchive::OpenArchive
|
|
|
|
//---------------------------------------------
|
2013-03-21 13:28:13 +04:00
|
|
|
nsresult nsZipArchive::OpenArchive(nsZipHandle *aZipHandle, PRFileDesc *aFd) {
|
2010-09-09 07:37:34 +04:00
|
|
|
mFd = aZipHandle;
|
1999-03-09 05:13:56 +03:00
|
|
|
|
2000-01-25 00:28:28 +03:00
|
|
|
//-- get table of contents for archive
|
2013-03-21 13:28:13 +04:00
|
|
|
nsresult rv = BuildFileList(aFd);
|
2013-02-19 14:02:12 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2019-03-08 01:54:53 +03:00
|
|
|
if (aZipHandle->mFile && XRE_IsParentProcess()) {
|
|
|
|
static char *env = PR_GetEnv("MOZ_JAR_LOG_FILE");
|
|
|
|
if (env) {
|
|
|
|
zipLog.Init(env);
|
2019-03-07 23:46:52 +03:00
|
|
|
// We only log accesses in jar/zip archives within the NS_GRE_DIR
|
|
|
|
// and/or the APK on Android. For the former, we log the archive path
|
|
|
|
// relative to NS_GRE_DIR, and for the latter, the nested-archive
|
|
|
|
// path within the APK. This makes the path match the path of the
|
|
|
|
// archives relative to the packaged dist/$APP_NAME directory in a
|
|
|
|
// build.
|
|
|
|
if (aZipHandle->mFile.IsZip()) {
|
|
|
|
// Nested archive, likely omni.ja in APK.
|
|
|
|
aZipHandle->mFile.GetPath(mURI);
|
|
|
|
} else if (nsDirectoryService::gService) {
|
|
|
|
// We can reach here through the initialization of Omnijar from
|
|
|
|
// XRE_InitCommandLine, which happens before the directory service
|
|
|
|
// is initialized. When that happens, it means the opened archive is
|
|
|
|
// the APK, and we don't care to log that one, so we just skip
|
|
|
|
// when the directory service is not initialized.
|
|
|
|
nsCOMPtr<nsIFile> dir = aZipHandle->mFile.GetBaseFile();
|
|
|
|
nsCOMPtr<nsIFile> gre_dir;
|
|
|
|
nsAutoCString path;
|
|
|
|
if (NS_SUCCEEDED(nsDirectoryService::gService->Get(
|
|
|
|
NS_GRE_DIR, NS_GET_IID(nsIFile), getter_AddRefs(gre_dir)))) {
|
|
|
|
nsAutoCString leaf;
|
|
|
|
nsCOMPtr<nsIFile> parent;
|
|
|
|
while (NS_SUCCEEDED(dir->GetNativeLeafName(leaf)) &&
|
|
|
|
NS_SUCCEEDED(dir->GetParent(getter_AddRefs(parent)))) {
|
|
|
|
if (!parent) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dir = parent;
|
|
|
|
if (path.Length()) {
|
|
|
|
path.Insert('/', 0);
|
|
|
|
}
|
|
|
|
path.Insert(leaf, 0);
|
|
|
|
bool equals;
|
|
|
|
if (NS_SUCCEEDED(dir->Equals(gre_dir, &equals)) && equals) {
|
|
|
|
mURI.Assign(path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-08 01:54:53 +03:00
|
|
|
}
|
|
|
|
}
|
2010-08-18 21:34:07 +04:00
|
|
|
}
|
|
|
|
return rv;
|
2000-01-25 00:28:28 +03:00
|
|
|
}
|
|
|
|
|
2015-07-30 11:05:57 +03:00
|
|
|
nsresult nsZipArchive::OpenArchive(nsIFile *aFile) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsZipHandle> handle;
|
2013-03-21 13:28:13 +04:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
mozilla::AutoFDClose fd;
|
2015-07-30 11:05:57 +03:00
|
|
|
nsresult rv = nsZipHandle::Init(aFile, getter_AddRefs(handle), &fd.rwget());
|
2013-03-21 13:28:13 +04:00
|
|
|
#else
|
2015-07-30 11:05:57 +03:00
|
|
|
nsresult rv = nsZipHandle::Init(aFile, getter_AddRefs(handle));
|
2013-03-21 13:28:13 +04:00
|
|
|
#endif
|
2010-09-09 07:37:34 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2013-03-21 13:28:13 +04:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
return OpenArchive(handle, fd.get());
|
|
|
|
#else
|
2010-09-09 07:37:34 +04:00
|
|
|
return OpenArchive(handle);
|
2013-03-21 13:28:13 +04:00
|
|
|
#endif
|
2010-09-09 07:37:34 +04:00
|
|
|
}
|
|
|
|
|
2000-12-27 10:05:55 +03:00
|
|
|
//---------------------------------------------
|
|
|
|
// nsZipArchive::Test
|
|
|
|
//---------------------------------------------
|
2006-05-02 23:33:09 +04:00
|
|
|
nsresult nsZipArchive::Test(const char *aEntryName) {
|
|
|
|
nsZipItem *currItem;
|
2000-12-27 10:05:55 +03:00
|
|
|
|
|
|
|
if (aEntryName) // only test specified item
|
|
|
|
{
|
2006-05-02 23:33:09 +04:00
|
|
|
currItem = GetItem(aEntryName);
|
2009-10-08 18:24:22 +04:00
|
|
|
if (!currItem) return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST;
|
2006-09-24 19:22:36 +04:00
|
|
|
//-- don't test (synthetic) directory items
|
2009-10-17 19:54:54 +04:00
|
|
|
if (currItem->IsDirectory()) return NS_OK;
|
2006-05-02 23:33:09 +04:00
|
|
|
return ExtractFile(currItem, 0, 0);
|
2000-12-27 10:05:55 +03:00
|
|
|
}
|
|
|
|
|
2006-05-02 23:33:09 +04:00
|
|
|
// test all items in archive
|
2017-02-08 14:06:26 +03:00
|
|
|
for (auto *item : mFiles) {
|
|
|
|
for (currItem = item; currItem; currItem = currItem->next) {
|
2006-09-24 19:22:36 +04:00
|
|
|
//-- don't test (synthetic) directory items
|
2009-10-17 19:54:54 +04:00
|
|
|
if (currItem->IsDirectory()) continue;
|
2006-05-02 23:33:09 +04:00
|
|
|
nsresult rv = ExtractFile(currItem, 0, 0);
|
2009-10-08 18:24:22 +04:00
|
|
|
if (rv != NS_OK) return rv;
|
2000-12-27 10:05:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-08 18:24:22 +04:00
|
|
|
return NS_OK;
|
2000-12-27 10:05:55 +03:00
|
|
|
}
|
|
|
|
|
1999-11-12 09:13:13 +03:00
|
|
|
//---------------------------------------------
|
|
|
|
// nsZipArchive::CloseArchive
|
|
|
|
//---------------------------------------------
|
2006-05-02 23:33:09 +04:00
|
|
|
nsresult nsZipArchive::CloseArchive() {
|
2006-05-06 00:44:52 +04:00
|
|
|
if (mFd) {
|
2017-04-05 21:16:43 +03:00
|
|
|
mArena.Clear();
|
2013-10-24 00:36:26 +04:00
|
|
|
mFd = nullptr;
|
2006-05-06 00:44:52 +04:00
|
|
|
}
|
2002-03-11 23:18:35 +03:00
|
|
|
|
|
|
|
// CAUTION:
|
2005-11-25 11:16:51 +03:00
|
|
|
// We don't need to delete each of the nsZipItem as the memory for
|
2002-03-11 23:18:35 +03:00
|
|
|
// the zip item and the filename it holds are both allocated from the Arena.
|
|
|
|
// Hence, destroying the Arena is like destroying all the memory
|
|
|
|
// for all the nsZipItem in one shot. But if the ~nsZipItem is doing
|
|
|
|
// anything more than cleaning up memory, we should start calling it.
|
2006-05-02 23:33:09 +04:00
|
|
|
// Let us also cleanup the mFiles table for re-use on the next 'open' call
|
2009-10-04 21:20:45 +04:00
|
|
|
memset(mFiles, 0, sizeof(mFiles));
|
|
|
|
mBuiltSynthetics = false;
|
2009-10-08 18:24:22 +04:00
|
|
|
return NS_OK;
|
1999-11-12 09:13:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------
|
2000-01-29 03:03:57 +03:00
|
|
|
// nsZipArchive::GetItem
|
1999-11-12 09:13:13 +03:00
|
|
|
//---------------------------------------------
|
2006-05-02 23:33:09 +04:00
|
|
|
nsZipItem *nsZipArchive::GetItem(const char *aEntryName) {
|
|
|
|
if (aEntryName) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = strlen(aEntryName);
|
2017-07-06 15:00:35 +03:00
|
|
|
//-- If the request is for a directory, make sure that synthetic entries
|
2006-09-24 19:22:36 +04:00
|
|
|
//-- are created for the directories without their own entry.
|
|
|
|
if (!mBuiltSynthetics) {
|
|
|
|
if ((len > 0) && (aEntryName[len - 1] == '/')) {
|
2009-10-08 18:24:22 +04:00
|
|
|
if (BuildSynthetics() != NS_OK) return 0;
|
2006-09-24 19:22:36 +04:00
|
|
|
}
|
|
|
|
}
|
2010-11-11 23:13:48 +03:00
|
|
|
MOZ_WIN_MEM_TRY_BEGIN
|
2009-10-17 19:54:54 +04:00
|
|
|
nsZipItem *item = mFiles[HashName(aEntryName, len)];
|
2006-05-02 23:33:09 +04:00
|
|
|
while (item) {
|
2017-07-06 15:00:35 +03:00
|
|
|
if ((len == item->nameLength) &&
|
2010-08-18 21:34:07 +04:00
|
|
|
(!memcmp(aEntryName, item->Name(), len))) {
|
2013-02-19 14:02:12 +04:00
|
|
|
// Successful GetItem() is a good indicator that the file is about to be
|
|
|
|
// read
|
2019-03-08 01:54:53 +03:00
|
|
|
if (mURI.Length()) {
|
|
|
|
zipLog.Write(mURI, aEntryName);
|
|
|
|
}
|
2006-05-02 23:33:09 +04:00
|
|
|
return item; //-- found it
|
2010-08-18 21:34:07 +04:00
|
|
|
}
|
2006-05-02 23:33:09 +04:00
|
|
|
item = item->next;
|
2002-10-31 09:27:20 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
MOZ_WIN_MEM_TRY_CATCH(return nullptr)
|
2003-02-01 00:53:39 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|
1999-04-28 04:34:30 +04:00
|
|
|
|
1999-03-09 05:13:56 +03:00
|
|
|
//---------------------------------------------
|
|
|
|
// nsZipArchive::ExtractFile
|
2006-05-02 23:33:09 +04:00
|
|
|
// This extracts the item to the filehandle provided.
|
|
|
|
// If 'aFd' is null, it only tests the extraction.
|
|
|
|
// On extraction error(s) it removes the file.
|
1999-03-09 05:13:56 +03:00
|
|
|
//---------------------------------------------
|
2017-12-15 14:58:51 +03:00
|
|
|
nsresult nsZipArchive::ExtractFile(nsZipItem *item, nsIFile *outFile,
|
2006-05-02 23:33:09 +04:00
|
|
|
PRFileDesc *aFd) {
|
2009-10-08 18:24:22 +04:00
|
|
|
if (!item) return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
if (!mFd) return NS_ERROR_FAILURE;
|
2004-08-17 04:12:04 +04:00
|
|
|
|
2006-03-30 02:10:37 +04:00
|
|
|
// Directory extraction is handled in nsJAR::Extract,
|
|
|
|
// so the item to be extracted should never be a directory
|
2016-06-28 20:47:22 +03:00
|
|
|
MOZ_ASSERT(!item->IsDirectory());
|
2006-03-30 02:10:37 +04:00
|
|
|
|
2010-06-05 01:10:23 +04:00
|
|
|
Bytef outbuf[ZIP_BUFLEN];
|
1999-03-09 05:13:56 +03:00
|
|
|
|
2010-06-05 01:10:23 +04:00
|
|
|
nsZipCursor cursor(item, this, outbuf, ZIP_BUFLEN, true);
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
1999-03-09 05:13:56 +03:00
|
|
|
|
2010-06-05 01:10:23 +04:00
|
|
|
while (true) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = 0;
|
|
|
|
uint8_t *buf = cursor.Read(&count);
|
2010-06-05 01:10:23 +04:00
|
|
|
if (!buf) {
|
|
|
|
rv = NS_ERROR_FILE_CORRUPTED;
|
|
|
|
break;
|
2017-02-09 12:54:30 +03:00
|
|
|
}
|
|
|
|
if (count == 0) {
|
2010-06-03 03:14:30 +04:00
|
|
|
break;
|
2010-06-05 01:10:23 +04:00
|
|
|
}
|
2010-06-03 04:05:49 +04:00
|
|
|
|
2010-06-05 01:10:23 +04:00
|
|
|
if (aFd && PR_Write(aFd, buf, count) < (READTYPE)count) {
|
|
|
|
rv = NS_ERROR_FILE_DISK_FULL;
|
|
|
|
break;
|
|
|
|
}
|
1999-03-09 05:13:56 +03:00
|
|
|
}
|
2000-03-28 07:38:06 +04:00
|
|
|
|
2017-11-21 19:25:46 +03:00
|
|
|
//-- delete the file on errors
|
2006-05-02 23:33:09 +04:00
|
|
|
if (aFd) {
|
|
|
|
PR_Close(aFd);
|
2017-12-15 14:58:51 +03:00
|
|
|
if (NS_FAILED(rv) && outFile) {
|
|
|
|
outFile->Remove(false);
|
|
|
|
}
|
2006-05-02 23:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1999-03-09 05:13:56 +03:00
|
|
|
}
|
|
|
|
|
1999-04-28 04:34:30 +04:00
|
|
|
//---------------------------------------------
|
|
|
|
// nsZipArchive::FindInit
|
|
|
|
//---------------------------------------------
|
2006-03-30 02:10:37 +04:00
|
|
|
nsresult nsZipArchive::FindInit(const char *aPattern, nsZipFind **aFind) {
|
2009-10-08 18:24:22 +04:00
|
|
|
if (!aFind) return NS_ERROR_ILLEGAL_VALUE;
|
2006-03-30 02:10:37 +04:00
|
|
|
|
|
|
|
// null out param in case an error happens
|
2013-10-24 00:36:26 +04:00
|
|
|
*aFind = nullptr;
|
2006-03-30 02:10:37 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool regExp = false;
|
1999-05-19 07:21:03 +04:00
|
|
|
char *pattern = 0;
|
|
|
|
|
2006-09-24 19:22:36 +04:00
|
|
|
// Create synthetic directory entries on demand
|
|
|
|
nsresult rv = BuildSynthetics();
|
2009-10-08 18:24:22 +04:00
|
|
|
if (rv != NS_OK) return rv;
|
2006-09-24 19:22:36 +04:00
|
|
|
|
1999-04-28 04:34:30 +04:00
|
|
|
// validate the pattern
|
2003-03-14 21:59:51 +03:00
|
|
|
if (aPattern) {
|
|
|
|
switch (NS_WildCardValid((char *)aPattern)) {
|
1999-04-28 04:34:30 +04:00
|
|
|
case INVALID_SXP:
|
2009-10-08 18:24:22 +04:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
1999-04-28 04:34:30 +04:00
|
|
|
|
|
|
|
case NON_SXP:
|
2011-10-17 18:59:28 +04:00
|
|
|
regExp = false;
|
1999-04-28 04:34:30 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VALID_SXP:
|
2011-10-17 18:59:28 +04:00
|
|
|
regExp = true;
|
1999-04-28 04:34:30 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1999-05-19 07:21:03 +04:00
|
|
|
// undocumented return value from RegExpValid!
|
2017-04-05 00:36:17 +03:00
|
|
|
MOZ_ASSERT(false);
|
2009-10-08 18:24:22 +04:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
1999-04-28 04:34:30 +04:00
|
|
|
}
|
|
|
|
|
2003-03-14 21:59:51 +03:00
|
|
|
pattern = PL_strdup(aPattern);
|
2009-10-08 18:24:22 +04:00
|
|
|
if (!pattern) return NS_ERROR_OUT_OF_MEMORY;
|
1999-04-28 04:34:30 +04:00
|
|
|
}
|
|
|
|
|
2006-03-30 02:10:37 +04:00
|
|
|
*aFind = new nsZipFind(this, pattern, regExp);
|
2006-09-24 19:22:36 +04:00
|
|
|
if (!*aFind) {
|
2009-04-07 13:24:58 +04:00
|
|
|
PL_strfree(pattern);
|
2009-10-08 18:24:22 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2006-09-24 19:22:36 +04:00
|
|
|
}
|
2006-03-30 02:10:37 +04:00
|
|
|
|
2009-10-08 18:24:22 +04:00
|
|
|
return NS_OK;
|
1999-04-28 04:34:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------
|
2006-05-02 23:33:09 +04:00
|
|
|
// nsZipFind::FindNext
|
1999-04-28 04:34:30 +04:00
|
|
|
//---------------------------------------------
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult nsZipFind::FindNext(const char **aResult, uint16_t *aNameLen) {
|
2009-10-17 19:54:54 +04:00
|
|
|
if (!mArchive || !aResult || !aNameLen) return NS_ERROR_ILLEGAL_VALUE;
|
1999-04-28 04:34:30 +04:00
|
|
|
|
2006-05-02 23:33:09 +04:00
|
|
|
*aResult = 0;
|
2009-10-17 19:54:54 +04:00
|
|
|
*aNameLen = 0;
|
2010-11-11 23:13:48 +03:00
|
|
|
MOZ_WIN_MEM_TRY_BEGIN
|
1999-04-28 04:34:30 +04:00
|
|
|
// we start from last match, look for next
|
2006-09-24 19:22:36 +04:00
|
|
|
while (mSlot < ZIP_TABSIZE) {
|
2006-05-02 23:33:09 +04:00
|
|
|
// move to next in current chain, or move to new slot
|
|
|
|
mItem = mItem ? mItem->next : mArchive->mFiles[mSlot];
|
1999-04-28 04:34:30 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool found = false;
|
2006-05-02 23:33:09 +04:00
|
|
|
if (!mItem)
|
|
|
|
++mSlot; // no more in this chain, move to next slot
|
|
|
|
else if (!mPattern)
|
2011-10-17 18:59:28 +04:00
|
|
|
found = true; // always match
|
2006-05-02 23:33:09 +04:00
|
|
|
else if (mRegExp) {
|
2009-10-17 19:54:54 +04:00
|
|
|
char buf[kMaxNameLength + 1];
|
|
|
|
memcpy(buf, mItem->Name(), mItem->nameLength);
|
|
|
|
buf[mItem->nameLength] = '\0';
|
2011-10-17 18:59:28 +04:00
|
|
|
found = (NS_WildCardMatch(buf, mPattern, false) == MATCH);
|
1999-04-28 04:34:30 +04:00
|
|
|
} else
|
2009-10-17 19:54:54 +04:00
|
|
|
found = ((mItem->nameLength == strlen(mPattern)) &&
|
|
|
|
(memcmp(mItem->Name(), mPattern, mItem->nameLength) == 0));
|
2006-09-24 19:22:36 +04:00
|
|
|
if (found) {
|
2009-10-17 19:54:54 +04:00
|
|
|
// Need also to return the name length, as it is NOT zero-terminatdd...
|
|
|
|
*aResult = mItem->Name();
|
|
|
|
*aNameLen = mItem->nameLength;
|
2009-10-08 18:24:22 +04:00
|
|
|
return NS_OK;
|
2006-03-30 02:10:37 +04:00
|
|
|
}
|
1999-04-28 04:34:30 +04:00
|
|
|
}
|
2010-11-11 23:13:48 +03:00
|
|
|
MOZ_WIN_MEM_TRY_CATCH(return NS_ERROR_FAILURE)
|
2009-10-08 18:24:22 +04:00
|
|
|
return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST;
|
1999-05-19 07:21:03 +04:00
|
|
|
}
|
|
|
|
|
1999-03-09 05:13:56 +03:00
|
|
|
//***********************************************************
|
|
|
|
// nsZipArchive -- private implementation
|
|
|
|
//***********************************************************
|
|
|
|
|
2006-03-30 02:10:37 +04:00
|
|
|
//---------------------------------------------
|
|
|
|
// nsZipArchive::CreateZipItem
|
|
|
|
//---------------------------------------------
|
2009-10-17 19:54:54 +04:00
|
|
|
nsZipItem *nsZipArchive::CreateZipItem() {
|
2006-03-30 02:10:37 +04:00
|
|
|
// Arena allocate the nsZipItem
|
2017-04-05 21:16:43 +03:00
|
|
|
return (nsZipItem *)mArena.Allocate(sizeof(nsZipItem));
|
2006-03-30 02:10:37 +04:00
|
|
|
}
|
|
|
|
|
1999-03-09 05:13:56 +03:00
|
|
|
//---------------------------------------------
|
|
|
|
// nsZipArchive::BuildFileList
|
|
|
|
//---------------------------------------------
|
2013-03-21 13:28:13 +04:00
|
|
|
nsresult nsZipArchive::BuildFileList(PRFileDesc *aFd) {
|
2009-08-25 02:12:02 +04:00
|
|
|
// Get archive size using end pos
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint8_t *buf;
|
|
|
|
const uint8_t *startp = mFd->mFileData;
|
|
|
|
const uint8_t *endp = startp + mFd->mLen;
|
2010-11-11 23:13:48 +03:00
|
|
|
MOZ_WIN_MEM_TRY_BEGIN
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t centralOffset = 4;
|
2019-02-26 02:40:55 +03:00
|
|
|
// Only perform readahead in the parent process. Children processes
|
|
|
|
// don't need readahead when the file has already been readahead by
|
|
|
|
// the parent process, and readahead only really happens for omni.ja,
|
|
|
|
// which is used in the parent process.
|
|
|
|
if (XRE_IsParentProcess() && mFd->mLen > ZIPCENTRAL_SIZE &&
|
2010-09-20 23:58:40 +04:00
|
|
|
xtolong(startp + centralOffset) == CENTRALSIG) {
|
2010-08-18 21:34:07 +04:00
|
|
|
// Success means optimized jar layout from bug 559961 is in effect
|
2013-03-21 13:28:13 +04:00
|
|
|
uint32_t readaheadLength = xtolong(startp);
|
2019-04-30 22:59:23 +03:00
|
|
|
mozilla::MaybePrefetchMemory(const_cast<uint8_t *>(startp),
|
|
|
|
readaheadLength);
|
2010-08-18 21:34:07 +04:00
|
|
|
} else {
|
|
|
|
for (buf = endp - ZIPEND_SIZE; buf > startp; buf--) {
|
|
|
|
if (xtolong(buf) == ENDSIG) {
|
|
|
|
centralOffset = xtolong(((ZipEnd *)buf)->offset_central_dir);
|
|
|
|
break;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2009-08-25 02:12:02 +04:00
|
|
|
}
|
2010-03-26 20:19:53 +03:00
|
|
|
|
2015-11-16 11:18:45 +03:00
|
|
|
if (!centralOffset) {
|
2010-03-26 20:19:53 +03:00
|
|
|
return NS_ERROR_FILE_CORRUPTED;
|
2015-11-16 11:18:45 +03:00
|
|
|
}
|
2001-01-22 23:15:49 +03:00
|
|
|
|
2009-10-17 19:54:54 +04:00
|
|
|
buf = startp + centralOffset;
|
2015-06-04 17:04:10 +03:00
|
|
|
|
|
|
|
// avoid overflow of startp + centralOffset.
|
2015-11-16 11:18:45 +03:00
|
|
|
if (buf < startp) {
|
2015-06-04 17:04:10 +03:00
|
|
|
return NS_ERROR_FILE_CORRUPTED;
|
2015-11-16 11:18:45 +03:00
|
|
|
}
|
2015-06-04 17:04:10 +03:00
|
|
|
|
|
|
|
//-- Read the central directory headers
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t sig = 0;
|
2016-05-24 00:06:44 +03:00
|
|
|
while ((buf + int32_t(sizeof(uint32_t)) > buf) &&
|
|
|
|
(buf + int32_t(sizeof(uint32_t)) <= endp) &&
|
|
|
|
((sig = xtolong(buf)) == CENTRALSIG)) {
|
2009-08-25 02:12:02 +04:00
|
|
|
// Make sure there is enough data available.
|
2016-05-12 18:33:47 +03:00
|
|
|
if ((buf > endp) || (endp - buf < ZIPCENTRAL_SIZE)) {
|
2009-10-08 18:24:22 +04:00
|
|
|
return NS_ERROR_FILE_CORRUPTED;
|
2015-11-16 11:18:45 +03:00
|
|
|
}
|
2001-04-03 10:35:13 +04:00
|
|
|
|
2009-08-25 02:12:02 +04:00
|
|
|
// Read the fixed-size data.
|
|
|
|
ZipCentral *central = (ZipCentral *)buf;
|
2001-04-03 10:35:13 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t namelen = xtoint(central->filename_len);
|
|
|
|
uint16_t extralen = xtoint(central->extrafield_len);
|
|
|
|
uint16_t commentlen = xtoint(central->commentfield_len);
|
2015-06-04 17:04:10 +03:00
|
|
|
uint32_t diff = ZIPCENTRAL_SIZE + namelen + extralen + commentlen;
|
2009-10-17 19:54:54 +04:00
|
|
|
|
2009-08-25 02:12:02 +04:00
|
|
|
// Sanity check variable sizes and refuse to deal with
|
|
|
|
// anything too big: it's likely a corrupt archive.
|
2015-11-16 11:18:45 +03:00
|
|
|
if (namelen < 1 || namelen > kMaxNameLength) {
|
|
|
|
return NS_ERROR_FILE_CORRUPTED;
|
|
|
|
}
|
|
|
|
if (buf >= buf + diff || // No overflow
|
2015-06-04 17:04:10 +03:00
|
|
|
buf >= endp - diff) {
|
2009-10-08 18:24:22 +04:00
|
|
|
return NS_ERROR_FILE_CORRUPTED;
|
2013-01-25 05:47:05 +04:00
|
|
|
}
|
2008-03-19 22:28:38 +03:00
|
|
|
|
2015-06-04 17:04:10 +03:00
|
|
|
// Point to the next item at the top of loop
|
|
|
|
buf += diff;
|
|
|
|
|
2009-10-17 19:54:54 +04:00
|
|
|
nsZipItem *item = CreateZipItem();
|
2009-10-08 18:24:22 +04:00
|
|
|
if (!item) return NS_ERROR_OUT_OF_MEMORY;
|
1999-03-09 05:13:56 +03:00
|
|
|
|
2009-10-17 19:54:54 +04:00
|
|
|
item->central = central;
|
|
|
|
item->nameLength = namelen;
|
|
|
|
item->isSynthetic = false;
|
2006-03-30 02:10:37 +04:00
|
|
|
|
2009-08-25 02:12:02 +04:00
|
|
|
// Add item to file table
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t hash = HashName(item->Name(), namelen);
|
2001-04-03 10:35:13 +04:00
|
|
|
item->next = mFiles[hash];
|
|
|
|
mFiles[hash] = item;
|
1999-11-02 23:37:28 +03:00
|
|
|
|
2011-05-22 20:38:02 +04:00
|
|
|
sig = 0;
|
2006-05-02 23:33:09 +04:00
|
|
|
} /* while reading central directory records */
|
2002-10-31 09:27:20 +03:00
|
|
|
|
2015-11-16 11:18:45 +03:00
|
|
|
if (sig != ENDSIG) {
|
2009-10-08 18:24:22 +04:00
|
|
|
return NS_ERROR_FILE_CORRUPTED;
|
2015-11-16 11:18:45 +03:00
|
|
|
}
|
2010-11-11 23:13:48 +03:00
|
|
|
|
2012-02-22 22:45:09 +04:00
|
|
|
// Make the comment available for consumers.
|
2016-05-12 18:33:47 +03:00
|
|
|
if ((endp >= buf) && (endp - buf >= ZIPEND_SIZE)) {
|
2012-02-22 22:45:09 +04:00
|
|
|
ZipEnd *zipend = (ZipEnd *)buf;
|
|
|
|
|
|
|
|
buf += ZIPEND_SIZE;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t commentlen = xtoint(zipend->commentfield_len);
|
2012-02-22 22:45:09 +04:00
|
|
|
if (endp - buf >= commentlen) {
|
|
|
|
mCommentPtr = (const char *)buf;
|
|
|
|
mCommentLen = commentlen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-11 23:13:48 +03:00
|
|
|
MOZ_WIN_MEM_TRY_CATCH(return NS_ERROR_FAILURE)
|
2009-10-08 18:24:22 +04:00
|
|
|
return NS_OK;
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|
|
|
|
|
2006-09-24 19:22:36 +04:00
|
|
|
//---------------------------------------------
|
|
|
|
// nsZipArchive::BuildSynthetics
|
|
|
|
//---------------------------------------------
|
|
|
|
nsresult nsZipArchive::BuildSynthetics() {
|
|
|
|
if (mBuiltSynthetics) return NS_OK;
|
2009-10-04 21:20:45 +04:00
|
|
|
mBuiltSynthetics = true;
|
2006-09-24 19:22:36 +04:00
|
|
|
|
2010-11-11 23:13:48 +03:00
|
|
|
MOZ_WIN_MEM_TRY_BEGIN
|
2006-09-24 19:22:36 +04:00
|
|
|
// Create synthetic entries for any missing directories.
|
|
|
|
// Do this when all ziptable has scanned to prevent double entries.
|
2017-02-08 14:06:26 +03:00
|
|
|
for (auto *item : mFiles) {
|
|
|
|
for (; item != nullptr; item = item->next) {
|
2006-09-24 19:22:36 +04:00
|
|
|
if (item->isSynthetic) continue;
|
2017-02-08 14:06:26 +03:00
|
|
|
|
2006-09-24 19:22:36 +04:00
|
|
|
//-- add entries for directories in the current item's path
|
|
|
|
//-- go from end to beginning, because then we can stop trying
|
|
|
|
//-- to create diritems if we find that the diritem we want to
|
|
|
|
//-- create already exists
|
|
|
|
//-- start just before the last char so as to not add the item
|
|
|
|
//-- twice if it's a directory
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t namelen = item->nameLength;
|
2013-01-25 05:47:05 +04:00
|
|
|
MOZ_ASSERT(namelen > 0,
|
|
|
|
"Attempt to build synthetic for zero-length entry name!");
|
2009-10-17 19:54:54 +04:00
|
|
|
const char *name = item->Name();
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint16_t dirlen = namelen - 1; dirlen > 0; dirlen--) {
|
2009-10-17 19:54:54 +04:00
|
|
|
if (name[dirlen - 1] != '/') continue;
|
2006-09-24 19:22:36 +04:00
|
|
|
|
2013-01-25 05:47:05 +04:00
|
|
|
// The character before this is '/', so if this is also '/' then we
|
|
|
|
// have an empty path component. Skip it.
|
|
|
|
if (name[dirlen] == '/') continue;
|
|
|
|
|
2009-10-17 19:54:54 +04:00
|
|
|
// Is the directory already in the file table?
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t hash = HashName(item->Name(), dirlen);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool found = false;
|
2013-10-24 00:36:26 +04:00
|
|
|
for (nsZipItem *zi = mFiles[hash]; zi != nullptr; zi = zi->next) {
|
2009-10-17 19:54:54 +04:00
|
|
|
if ((dirlen == zi->nameLength) &&
|
|
|
|
(0 == memcmp(item->Name(), zi->Name(), dirlen))) {
|
2006-09-24 19:22:36 +04:00
|
|
|
// we've already added this dir and all its parents
|
2011-10-17 18:59:28 +04:00
|
|
|
found = true;
|
2006-09-24 19:22:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if the directory was found, break out of the directory
|
|
|
|
// creation loop now that we know all implicit directories
|
|
|
|
// are there -- otherwise, start creating the zip item
|
|
|
|
if (found) break;
|
|
|
|
|
2009-10-17 19:54:54 +04:00
|
|
|
nsZipItem *diritem = CreateZipItem();
|
2009-10-08 18:24:22 +04:00
|
|
|
if (!diritem) return NS_ERROR_OUT_OF_MEMORY;
|
2006-09-24 19:22:36 +04:00
|
|
|
|
2009-10-17 19:54:54 +04:00
|
|
|
// Point to the central record of the original item for the name part.
|
|
|
|
diritem->central = item->central;
|
|
|
|
diritem->nameLength = dirlen;
|
|
|
|
diritem->isSynthetic = true;
|
2006-09-24 19:22:36 +04:00
|
|
|
|
|
|
|
// add diritem to the file table
|
|
|
|
diritem->next = mFiles[hash];
|
|
|
|
mFiles[hash] = diritem;
|
|
|
|
} /* end processing of dirs in item's name */
|
|
|
|
}
|
|
|
|
}
|
2010-11-11 23:13:48 +03:00
|
|
|
MOZ_WIN_MEM_TRY_CATCH(return NS_ERROR_FAILURE)
|
2009-10-08 18:24:22 +04:00
|
|
|
return NS_OK;
|
2006-09-24 19:22:36 +04:00
|
|
|
}
|
|
|
|
|
2009-10-04 21:20:45 +04:00
|
|
|
nsZipHandle *nsZipArchive::GetFD() {
|
2013-10-24 00:36:26 +04:00
|
|
|
if (!mFd) return nullptr;
|
2009-08-13 00:50:12 +04:00
|
|
|
return mFd.get();
|
|
|
|
}
|
1999-10-26 23:43:26 +04:00
|
|
|
|
|
|
|
//---------------------------------------------
|
2014-05-16 09:34:43 +04:00
|
|
|
// nsZipArchive::GetDataOffset
|
1999-10-26 23:43:26 +04:00
|
|
|
//---------------------------------------------
|
2014-05-16 09:34:43 +04:00
|
|
|
uint32_t nsZipArchive::GetDataOffset(nsZipItem *aItem) {
|
2016-06-28 20:47:22 +03:00
|
|
|
MOZ_ASSERT(aItem);
|
2010-11-11 23:13:48 +03:00
|
|
|
MOZ_WIN_MEM_TRY_BEGIN
|
2009-10-04 21:20:45 +04:00
|
|
|
//-- read local header to get variable length values and calculate
|
|
|
|
//-- the real data offset
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = mFd->mLen;
|
|
|
|
const uint8_t *data = mFd->mFileData;
|
|
|
|
uint32_t offset = aItem->LocalOffset();
|
2015-06-04 17:04:10 +03:00
|
|
|
if (len < ZIPLOCAL_SIZE || offset > len - ZIPLOCAL_SIZE) return 0;
|
2009-09-01 23:47:00 +04:00
|
|
|
|
2009-10-04 21:20:45 +04:00
|
|
|
// -- check signature before using the structure, in case the zip file is
|
|
|
|
// corrupt
|
2009-10-17 19:54:54 +04:00
|
|
|
ZipLocal *Local = (ZipLocal *)(data + offset);
|
2009-10-04 21:20:45 +04:00
|
|
|
if ((xtolong(Local->signature) != LOCALSIG)) return 0;
|
|
|
|
|
|
|
|
//-- NOTE: extralen is different in central header and local header
|
|
|
|
//-- for archives created using the Unix "zip" utility. To set
|
|
|
|
//-- the offset accurately we need the _local_ extralen.
|
2009-10-17 19:54:54 +04:00
|
|
|
offset += ZIPLOCAL_SIZE + xtoint(Local->filename_len) +
|
|
|
|
xtoint(Local->extrafield_len);
|
2001-04-03 10:35:13 +04:00
|
|
|
|
2014-05-16 09:34:43 +04:00
|
|
|
return offset;
|
|
|
|
MOZ_WIN_MEM_TRY_CATCH(return 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------
|
|
|
|
// nsZipArchive::GetData
|
|
|
|
//---------------------------------------------
|
|
|
|
const uint8_t *nsZipArchive::GetData(nsZipItem *aItem) {
|
2016-06-28 20:47:22 +03:00
|
|
|
MOZ_ASSERT(aItem);
|
2014-05-16 09:34:43 +04:00
|
|
|
MOZ_WIN_MEM_TRY_BEGIN
|
|
|
|
uint32_t offset = GetDataOffset(aItem);
|
|
|
|
|
2009-10-04 21:20:45 +04:00
|
|
|
// -- check if there is enough source data in the file
|
2015-06-04 17:04:10 +03:00
|
|
|
if (!offset || mFd->mLen < aItem->Size() ||
|
2015-10-13 21:20:25 +03:00
|
|
|
offset > mFd->mLen - aItem->Size() ||
|
|
|
|
(aItem->Compression() == STORED && aItem->Size() != aItem->RealSize())) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2015-10-13 21:20:25 +03:00
|
|
|
}
|
2009-10-04 21:20:45 +04:00
|
|
|
|
2014-05-16 09:34:43 +04:00
|
|
|
return mFd->mFileData + offset;
|
2012-07-30 18:20:58 +04:00
|
|
|
MOZ_WIN_MEM_TRY_CATCH(return nullptr)
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|
1999-03-09 05:13:56 +03:00
|
|
|
|
2012-02-22 22:45:09 +04:00
|
|
|
// nsZipArchive::GetComment
|
|
|
|
bool nsZipArchive::GetComment(nsACString &aComment) {
|
|
|
|
MOZ_WIN_MEM_TRY_BEGIN
|
|
|
|
aComment.Assign(mCommentPtr, mCommentLen);
|
|
|
|
MOZ_WIN_MEM_TRY_CATCH(return false)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-25 04:50:47 +04:00
|
|
|
//---------------------------------------------
|
|
|
|
// nsZipArchive::SizeOfMapping
|
|
|
|
//---------------------------------------------
|
|
|
|
int64_t nsZipArchive::SizeOfMapping() { return mFd ? mFd->SizeOfMapping() : 0; }
|
|
|
|
|
1999-03-09 05:13:56 +03:00
|
|
|
//------------------------------------------
|
|
|
|
// nsZipArchive constructor and destructor
|
|
|
|
//------------------------------------------
|
|
|
|
|
2011-12-08 14:03:36 +04:00
|
|
|
nsZipArchive::nsZipArchive()
|
|
|
|
: mRefCnt(0),
|
2015-10-20 14:32:47 +03:00
|
|
|
mCommentPtr(nullptr),
|
|
|
|
mCommentLen(0),
|
2011-12-08 14:03:36 +04:00
|
|
|
mBuiltSynthetics(false) {
|
2013-02-19 14:02:12 +04:00
|
|
|
zipLog.AddRef();
|
|
|
|
|
2013-10-24 00:36:26 +04:00
|
|
|
// initialize the table to nullptr
|
2009-10-04 21:20:45 +04:00
|
|
|
memset(mFiles, 0, sizeof(mFiles));
|
1999-03-09 05:13:56 +03:00
|
|
|
}
|
|
|
|
|
2013-07-19 06:23:44 +04:00
|
|
|
NS_IMPL_ADDREF(nsZipArchive)
|
|
|
|
NS_IMPL_RELEASE(nsZipArchive)
|
2011-12-08 14:03:36 +04:00
|
|
|
|
1999-03-09 05:13:56 +03:00
|
|
|
nsZipArchive::~nsZipArchive() {
|
2003-03-14 21:59:51 +03:00
|
|
|
CloseArchive();
|
1999-11-16 04:52:29 +03:00
|
|
|
|
2013-02-19 14:02:12 +04:00
|
|
|
zipLog.Release();
|
1999-03-09 05:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|
2006-05-02 23:33:09 +04:00
|
|
|
// nsZipFind constructor and destructor
|
1999-03-09 05:13:56 +03:00
|
|
|
//------------------------------------------
|
|
|
|
|
2015-10-20 14:32:47 +03:00
|
|
|
nsZipFind::nsZipFind(nsZipArchive *aZip, char *aPattern, bool aRegExp)
|
|
|
|
: mArchive(aZip),
|
|
|
|
mPattern(aPattern),
|
|
|
|
mItem(nullptr),
|
|
|
|
mSlot(0),
|
|
|
|
mRegExp(aRegExp) {
|
1999-11-16 04:52:29 +03:00
|
|
|
MOZ_COUNT_CTOR(nsZipFind);
|
|
|
|
}
|
1999-05-19 07:21:03 +04:00
|
|
|
|
|
|
|
nsZipFind::~nsZipFind() {
|
2009-04-07 13:24:58 +04:00
|
|
|
PL_strfree(mPattern);
|
1999-11-16 04:52:29 +03:00
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(nsZipFind);
|
1999-05-19 07:21:03 +04:00
|
|
|
}
|
|
|
|
|
1999-06-23 10:16:28 +04:00
|
|
|
//------------------------------------------
|
2006-05-02 23:33:09 +04:00
|
|
|
// helper functions
|
1999-06-23 10:16:28 +04:00
|
|
|
//------------------------------------------
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
/*
|
|
|
|
* HashName
|
2006-05-02 23:33:09 +04:00
|
|
|
*
|
2017-07-06 15:00:35 +03:00
|
|
|
* returns a hash key for the entry name
|
2006-05-02 23:33:09 +04:00
|
|
|
*/
|
2018-03-02 04:11:39 +03:00
|
|
|
MOZ_NO_SANITIZE_UNSIGNED_OVERFLOW
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t HashName(const char *aName, uint16_t len) {
|
2016-06-28 20:47:22 +03:00
|
|
|
MOZ_ASSERT(aName != 0);
|
1999-06-23 10:16:28 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint8_t *p = (const uint8_t *)aName;
|
|
|
|
const uint8_t *endp = p + len;
|
|
|
|
uint32_t val = 0;
|
2009-10-17 19:54:54 +04:00
|
|
|
while (p != endp) {
|
|
|
|
val = val * 37 + *p++;
|
2006-05-02 23:33:09 +04:00
|
|
|
}
|
1999-05-19 07:21:03 +04:00
|
|
|
|
2006-05-02 23:33:09 +04:00
|
|
|
return (val % ZIP_TABSIZE);
|
|
|
|
}
|
1999-03-09 05:13:56 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* x t o i n t
|
|
|
|
*
|
|
|
|
* Converts a two byte ugly endianed integer
|
|
|
|
* to our platform's integer.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint16_t xtoint(const uint8_t *ii) {
|
|
|
|
return (uint16_t)((ii[0]) | (ii[1] << 8));
|
1999-03-09 05:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* x t o l o n g
|
|
|
|
*
|
|
|
|
* Converts a four byte ugly endianed integer
|
|
|
|
* to our platform's integer.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t xtolong(const uint8_t *ll) {
|
|
|
|
return (uint32_t)((ll[0] << 0) | (ll[1] << 8) | (ll[2] << 16) |
|
2006-05-02 23:33:09 +04:00
|
|
|
(ll[3] << 24));
|
1999-03-09 05:13:56 +03:00
|
|
|
}
|
1999-06-23 10:16:28 +04:00
|
|
|
|
2009-12-16 02:01:08 +03:00
|
|
|
/*
|
|
|
|
* GetModTime
|
|
|
|
*
|
|
|
|
* returns last modification time in microseconds
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static PRTime GetModTime(uint16_t aDate, uint16_t aTime) {
|
2009-12-16 02:01:08 +03:00
|
|
|
// Note that on DST shift we can't handle correctly the hour that is valid
|
|
|
|
// in both DST zones
|
|
|
|
PRExplodedTime time;
|
|
|
|
|
|
|
|
time.tm_usec = 0;
|
|
|
|
|
|
|
|
time.tm_hour = (aTime >> 11) & 0x1F;
|
|
|
|
time.tm_min = (aTime >> 5) & 0x3F;
|
|
|
|
time.tm_sec = (aTime & 0x1F) * 2;
|
|
|
|
|
|
|
|
time.tm_year = (aDate >> 9) + 1980;
|
|
|
|
time.tm_month = ((aDate >> 5) & 0x0F) - 1;
|
|
|
|
time.tm_mday = aDate & 0x1F;
|
|
|
|
|
|
|
|
time.tm_params.tp_gmt_offset = 0;
|
|
|
|
time.tm_params.tp_dst_offset = 0;
|
|
|
|
|
|
|
|
PR_NormalizeTime(&time, PR_GMTParameters);
|
|
|
|
time.tm_params.tp_gmt_offset = PR_LocalTimeParameters(&time).tp_gmt_offset;
|
|
|
|
PR_NormalizeTime(&time, PR_GMTParameters);
|
|
|
|
time.tm_params.tp_dst_offset = PR_LocalTimeParameters(&time).tp_dst_offset;
|
|
|
|
|
|
|
|
return PR_ImplodeTime(&time);
|
|
|
|
}
|
|
|
|
|
2015-10-20 14:32:47 +03:00
|
|
|
nsZipItem::nsZipItem()
|
|
|
|
: next(nullptr), central(nullptr), nameLength(0), isSynthetic(false) {}
|
1999-06-23 10:16:28 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t nsZipItem::LocalOffset() { return xtolong(central->localhdr_offset); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-10-17 19:54:54 +04:00
|
|
|
uint32_t nsZipItem::Size() { return isSynthetic ? 0 : xtolong(central->size); }
|
2001-09-21 03:33:23 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t nsZipItem::RealSize() {
|
2009-10-17 19:54:54 +04:00
|
|
|
return isSynthetic ? 0 : xtolong(central->orglen);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t nsZipItem::CRC32() {
|
2009-10-17 19:54:54 +04:00
|
|
|
return isSynthetic ? 0 : xtolong(central->crc32);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t nsZipItem::Date() {
|
2009-10-17 19:54:54 +04:00
|
|
|
return isSynthetic ? kSyntheticDate : xtoint(central->date);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t nsZipItem::Time() {
|
2009-10-17 19:54:54 +04:00
|
|
|
return isSynthetic ? kSyntheticTime : xtoint(central->time);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t nsZipItem::Compression() {
|
2009-10-17 19:54:54 +04:00
|
|
|
return isSynthetic ? STORED : xtoint(central->method);
|
|
|
|
}
|
|
|
|
|
2009-12-16 02:01:08 +03:00
|
|
|
bool nsZipItem::IsDirectory() {
|
2009-10-17 19:54:54 +04:00
|
|
|
return isSynthetic || ((nameLength > 0) && ('/' == Name()[nameLength - 1]));
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t nsZipItem::Mode() {
|
2009-10-17 19:54:54 +04:00
|
|
|
if (isSynthetic) return 0755;
|
2012-08-22 19:56:38 +04:00
|
|
|
return ((uint16_t)(central->external_attributes[2]) | 0x100);
|
2009-10-17 19:54:54 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint8_t *nsZipItem::GetExtraField(uint16_t aTag, uint16_t *aBlockSize) {
|
2012-07-30 18:20:58 +04:00
|
|
|
if (isSynthetic) return nullptr;
|
2010-11-11 23:13:48 +03:00
|
|
|
MOZ_WIN_MEM_TRY_BEGIN
|
2009-12-16 02:01:08 +03:00
|
|
|
const unsigned char *buf =
|
|
|
|
((const unsigned char *)central) + ZIPCENTRAL_SIZE + nameLength;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t buflen = (uint32_t)xtoint(central->extrafield_len);
|
|
|
|
uint32_t pos = 0;
|
|
|
|
uint16_t tag, blocksize;
|
2009-12-16 02:01:08 +03:00
|
|
|
|
|
|
|
while (buf && (pos + 4) <= buflen) {
|
|
|
|
tag = xtoint(buf + pos);
|
|
|
|
blocksize = xtoint(buf + pos + 2);
|
|
|
|
|
|
|
|
if (aTag == tag && (pos + 4 + blocksize) <= buflen) {
|
|
|
|
*aBlockSize = blocksize;
|
|
|
|
return buf + pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos += blocksize + 4;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
MOZ_WIN_MEM_TRY_CATCH(return nullptr)
|
|
|
|
return nullptr;
|
2009-12-16 02:01:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRTime nsZipItem::LastModTime() {
|
|
|
|
if (isSynthetic) return GetModTime(kSyntheticDate, kSyntheticTime);
|
|
|
|
|
|
|
|
// Try to read timestamp from extra field
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t blocksize;
|
|
|
|
const uint8_t *tsField = GetExtraField(EXTENDED_TIMESTAMP_FIELD, &blocksize);
|
2009-12-16 02:01:08 +03:00
|
|
|
if (tsField && blocksize >= 5 && tsField[4] & EXTENDED_TIMESTAMP_MODTIME) {
|
|
|
|
return (PRTime)(xtolong(tsField + 5)) * PR_USEC_PER_SEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetModTime(Date(), Time());
|
|
|
|
}
|
|
|
|
|
2015-10-20 14:32:47 +03:00
|
|
|
nsZipCursor::nsZipCursor(nsZipItem *item, nsZipArchive *aZip, uint8_t *aBuf,
|
|
|
|
uint32_t aBufSize, bool doCRC)
|
|
|
|
: mItem(item),
|
|
|
|
mBuf(aBuf),
|
|
|
|
mBufSize(aBufSize),
|
2018-06-16 14:03:28 +03:00
|
|
|
mZs()
|
Bug 1355661 - Add support for brotli streams in Jar archives. r=aklotz
Modern compression algorithms are better than zlib both in terms of
space and time. The jar format, used for e.g. omni.ja, addons, etc.
could benefit from using such modern algorithms, but the format only
allows a limited set of compression algorithms.
However, the format in itself is flexible, in that it can be extended
with arbitrary compression algorithms. This breaks compatibility with
programs like unzip, obviously, but we've never promised the files
shipped with Firefox will always remain "valid" zips (which they already
aren't, but they currently work with most zip readers).
With this change, we allow those archives to contain brotli streams,
using an arbitrary large value for the compression type in the Zip local
file header. This only allows to read such archives, but not to produce
them, and, for now, support for brotli streams is kept Nightly-only,
until everything is pieced together and we're happy to ship it.
--HG--
extra : rebase_source : fa637251f460ad0d91d5f5bec392c6e59555e80d
2017-04-07 08:48:25 +03:00
|
|
|
#ifdef MOZ_JAR_BROTLI
|
|
|
|
,
|
|
|
|
mBrotliState(nullptr)
|
|
|
|
#endif
|
2015-10-20 14:32:47 +03:00
|
|
|
,
|
|
|
|
mCRC(0),
|
|
|
|
mDoCRC(doCRC) {
|
2010-06-05 01:10:23 +04:00
|
|
|
if (mItem->Compression() == DEFLATED) {
|
2010-07-11 16:49:52 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult status =
|
|
|
|
#endif
|
|
|
|
gZlibInit(&mZs);
|
2010-06-05 01:10:23 +04:00
|
|
|
NS_ASSERTION(status == NS_OK, "Zlib failed to initialize");
|
|
|
|
NS_ASSERTION(aBuf, "Must pass in a buffer for DEFLATED nsZipItem");
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2010-06-05 01:10:23 +04:00
|
|
|
mZs.avail_in = item->Size();
|
|
|
|
mZs.next_in = (Bytef *)aZip->GetData(item);
|
Bug 1355661 - Add support for brotli streams in Jar archives. r=aklotz
Modern compression algorithms are better than zlib both in terms of
space and time. The jar format, used for e.g. omni.ja, addons, etc.
could benefit from using such modern algorithms, but the format only
allows a limited set of compression algorithms.
However, the format in itself is flexible, in that it can be extended
with arbitrary compression algorithms. This breaks compatibility with
programs like unzip, obviously, but we've never promised the files
shipped with Firefox will always remain "valid" zips (which they already
aren't, but they currently work with most zip readers).
With this change, we allow those archives to contain brotli streams,
using an arbitrary large value for the compression type in the Zip local
file header. This only allows to read such archives, but not to produce
them, and, for now, support for brotli streams is kept Nightly-only,
until everything is pieced together and we're happy to ship it.
--HG--
extra : rebase_source : fa637251f460ad0d91d5f5bec392c6e59555e80d
2017-04-07 08:48:25 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_JAR_BROTLI
|
|
|
|
if (mItem->Compression() == MOZ_JAR_BROTLI) {
|
2017-08-09 13:45:39 +03:00
|
|
|
mBrotliState = BrotliDecoderCreateInstance(nullptr, nullptr, nullptr);
|
Bug 1355661 - Add support for brotli streams in Jar archives. r=aklotz
Modern compression algorithms are better than zlib both in terms of
space and time. The jar format, used for e.g. omni.ja, addons, etc.
could benefit from using such modern algorithms, but the format only
allows a limited set of compression algorithms.
However, the format in itself is flexible, in that it can be extended
with arbitrary compression algorithms. This breaks compatibility with
programs like unzip, obviously, but we've never promised the files
shipped with Firefox will always remain "valid" zips (which they already
aren't, but they currently work with most zip readers).
With this change, we allow those archives to contain brotli streams,
using an arbitrary large value for the compression type in the Zip local
file header. This only allows to read such archives, but not to produce
them, and, for now, support for brotli streams is kept Nightly-only,
until everything is pieced together and we're happy to ship it.
--HG--
extra : rebase_source : fa637251f460ad0d91d5f5bec392c6e59555e80d
2017-04-07 08:48:25 +03:00
|
|
|
}
|
|
|
|
#endif
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2010-06-05 01:10:23 +04:00
|
|
|
if (doCRC) mCRC = crc32(0L, Z_NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsZipCursor::~nsZipCursor() {
|
|
|
|
if (mItem->Compression() == DEFLATED) {
|
|
|
|
inflateEnd(&mZs);
|
|
|
|
}
|
Bug 1355661 - Add support for brotli streams in Jar archives. r=aklotz
Modern compression algorithms are better than zlib both in terms of
space and time. The jar format, used for e.g. omni.ja, addons, etc.
could benefit from using such modern algorithms, but the format only
allows a limited set of compression algorithms.
However, the format in itself is flexible, in that it can be extended
with arbitrary compression algorithms. This breaks compatibility with
programs like unzip, obviously, but we've never promised the files
shipped with Firefox will always remain "valid" zips (which they already
aren't, but they currently work with most zip readers).
With this change, we allow those archives to contain brotli streams,
using an arbitrary large value for the compression type in the Zip local
file header. This only allows to read such archives, but not to produce
them, and, for now, support for brotli streams is kept Nightly-only,
until everything is pieced together and we're happy to ship it.
--HG--
extra : rebase_source : fa637251f460ad0d91d5f5bec392c6e59555e80d
2017-04-07 08:48:25 +03:00
|
|
|
#ifdef MOZ_JAR_BROTLI
|
|
|
|
if (mItem->Compression() == MOZ_JAR_BROTLI) {
|
2017-08-09 13:45:39 +03:00
|
|
|
BrotliDecoderDestroyInstance(mBrotliState);
|
Bug 1355661 - Add support for brotli streams in Jar archives. r=aklotz
Modern compression algorithms are better than zlib both in terms of
space and time. The jar format, used for e.g. omni.ja, addons, etc.
could benefit from using such modern algorithms, but the format only
allows a limited set of compression algorithms.
However, the format in itself is flexible, in that it can be extended
with arbitrary compression algorithms. This breaks compatibility with
programs like unzip, obviously, but we've never promised the files
shipped with Firefox will always remain "valid" zips (which they already
aren't, but they currently work with most zip readers).
With this change, we allow those archives to contain brotli streams,
using an arbitrary large value for the compression type in the Zip local
file header. This only allows to read such archives, but not to produce
them, and, for now, support for brotli streams is kept Nightly-only,
until everything is pieced together and we're happy to ship it.
--HG--
extra : rebase_source : fa637251f460ad0d91d5f5bec392c6e59555e80d
2017-04-07 08:48:25 +03:00
|
|
|
}
|
|
|
|
#endif
|
2010-06-05 01:10:23 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t *nsZipCursor::ReadOrCopy(uint32_t *aBytesRead, bool aCopy) {
|
2010-06-05 01:10:23 +04:00
|
|
|
int zerr;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t *buf = nullptr;
|
2010-06-05 01:10:23 +04:00
|
|
|
bool verifyCRC = true;
|
|
|
|
|
|
|
|
if (!mZs.next_in) return nullptr;
|
2010-11-11 23:13:48 +03:00
|
|
|
MOZ_WIN_MEM_TRY_BEGIN
|
2010-06-05 01:10:23 +04:00
|
|
|
switch (mItem->Compression()) {
|
|
|
|
case STORED:
|
2011-12-08 14:03:36 +04:00
|
|
|
if (!aCopy) {
|
|
|
|
*aBytesRead = mZs.avail_in;
|
|
|
|
buf = mZs.next_in;
|
|
|
|
mZs.next_in += mZs.avail_in;
|
|
|
|
mZs.avail_in = 0;
|
|
|
|
} else {
|
|
|
|
*aBytesRead = mZs.avail_in > mBufSize ? mBufSize : mZs.avail_in;
|
|
|
|
memcpy(mBuf, mZs.next_in, *aBytesRead);
|
|
|
|
mZs.avail_in -= *aBytesRead;
|
|
|
|
mZs.next_in += *aBytesRead;
|
|
|
|
}
|
2010-06-05 01:10:23 +04:00
|
|
|
break;
|
|
|
|
case DEFLATED:
|
|
|
|
buf = mBuf;
|
|
|
|
mZs.next_out = buf;
|
|
|
|
mZs.avail_out = mBufSize;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-06-05 01:10:23 +04:00
|
|
|
zerr = inflate(&mZs, Z_PARTIAL_FLUSH);
|
|
|
|
if (zerr != Z_OK && zerr != Z_STREAM_END) return nullptr;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2010-06-05 01:10:23 +04:00
|
|
|
*aBytesRead = mZs.next_out - buf;
|
|
|
|
verifyCRC = (zerr == Z_STREAM_END);
|
|
|
|
break;
|
Bug 1355661 - Add support for brotli streams in Jar archives. r=aklotz
Modern compression algorithms are better than zlib both in terms of
space and time. The jar format, used for e.g. omni.ja, addons, etc.
could benefit from using such modern algorithms, but the format only
allows a limited set of compression algorithms.
However, the format in itself is flexible, in that it can be extended
with arbitrary compression algorithms. This breaks compatibility with
programs like unzip, obviously, but we've never promised the files
shipped with Firefox will always remain "valid" zips (which they already
aren't, but they currently work with most zip readers).
With this change, we allow those archives to contain brotli streams,
using an arbitrary large value for the compression type in the Zip local
file header. This only allows to read such archives, but not to produce
them, and, for now, support for brotli streams is kept Nightly-only,
until everything is pieced together and we're happy to ship it.
--HG--
extra : rebase_source : fa637251f460ad0d91d5f5bec392c6e59555e80d
2017-04-07 08:48:25 +03:00
|
|
|
#ifdef MOZ_JAR_BROTLI
|
|
|
|
case MOZ_JAR_BROTLI: {
|
|
|
|
buf = mBuf;
|
|
|
|
mZs.next_out = buf;
|
|
|
|
/* The brotli library wants size_t, but z_stream only contains
|
|
|
|
* unsigned int for avail_*. So use temporary stack values. */
|
|
|
|
size_t avail_out = mBufSize;
|
|
|
|
size_t avail_in = mZs.avail_in;
|
2017-08-09 13:45:39 +03:00
|
|
|
BrotliDecoderResult result = BrotliDecoderDecompressStream(
|
|
|
|
mBrotliState, &avail_in,
|
Bug 1355661 - Add support for brotli streams in Jar archives. r=aklotz
Modern compression algorithms are better than zlib both in terms of
space and time. The jar format, used for e.g. omni.ja, addons, etc.
could benefit from using such modern algorithms, but the format only
allows a limited set of compression algorithms.
However, the format in itself is flexible, in that it can be extended
with arbitrary compression algorithms. This breaks compatibility with
programs like unzip, obviously, but we've never promised the files
shipped with Firefox will always remain "valid" zips (which they already
aren't, but they currently work with most zip readers).
With this change, we allow those archives to contain brotli streams,
using an arbitrary large value for the compression type in the Zip local
file header. This only allows to read such archives, but not to produce
them, and, for now, support for brotli streams is kept Nightly-only,
until everything is pieced together and we're happy to ship it.
--HG--
extra : rebase_source : fa637251f460ad0d91d5f5bec392c6e59555e80d
2017-04-07 08:48:25 +03:00
|
|
|
const_cast<const unsigned char **>(&mZs.next_in), &avail_out,
|
2017-08-09 13:45:39 +03:00
|
|
|
&mZs.next_out, nullptr);
|
Bug 1355661 - Add support for brotli streams in Jar archives. r=aklotz
Modern compression algorithms are better than zlib both in terms of
space and time. The jar format, used for e.g. omni.ja, addons, etc.
could benefit from using such modern algorithms, but the format only
allows a limited set of compression algorithms.
However, the format in itself is flexible, in that it can be extended
with arbitrary compression algorithms. This breaks compatibility with
programs like unzip, obviously, but we've never promised the files
shipped with Firefox will always remain "valid" zips (which they already
aren't, but they currently work with most zip readers).
With this change, we allow those archives to contain brotli streams,
using an arbitrary large value for the compression type in the Zip local
file header. This only allows to read such archives, but not to produce
them, and, for now, support for brotli streams is kept Nightly-only,
until everything is pieced together and we're happy to ship it.
--HG--
extra : rebase_source : fa637251f460ad0d91d5f5bec392c6e59555e80d
2017-04-07 08:48:25 +03:00
|
|
|
/* We don't need to update avail_out, it's not used outside this
|
|
|
|
* function. */
|
|
|
|
mZs.avail_in = avail_in;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-09 13:45:39 +03:00
|
|
|
if (result == BROTLI_DECODER_RESULT_ERROR) {
|
Bug 1355661 - Add support for brotli streams in Jar archives. r=aklotz
Modern compression algorithms are better than zlib both in terms of
space and time. The jar format, used for e.g. omni.ja, addons, etc.
could benefit from using such modern algorithms, but the format only
allows a limited set of compression algorithms.
However, the format in itself is flexible, in that it can be extended
with arbitrary compression algorithms. This breaks compatibility with
programs like unzip, obviously, but we've never promised the files
shipped with Firefox will always remain "valid" zips (which they already
aren't, but they currently work with most zip readers).
With this change, we allow those archives to contain brotli streams,
using an arbitrary large value for the compression type in the Zip local
file header. This only allows to read such archives, but not to produce
them, and, for now, support for brotli streams is kept Nightly-only,
until everything is pieced together and we're happy to ship it.
--HG--
extra : rebase_source : fa637251f460ad0d91d5f5bec392c6e59555e80d
2017-04-07 08:48:25 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aBytesRead = mZs.next_out - buf;
|
2017-08-09 13:45:39 +03:00
|
|
|
verifyCRC = (result == BROTLI_DECODER_RESULT_SUCCESS);
|
Bug 1355661 - Add support for brotli streams in Jar archives. r=aklotz
Modern compression algorithms are better than zlib both in terms of
space and time. The jar format, used for e.g. omni.ja, addons, etc.
could benefit from using such modern algorithms, but the format only
allows a limited set of compression algorithms.
However, the format in itself is flexible, in that it can be extended
with arbitrary compression algorithms. This breaks compatibility with
programs like unzip, obviously, but we've never promised the files
shipped with Firefox will always remain "valid" zips (which they already
aren't, but they currently work with most zip readers).
With this change, we allow those archives to contain brotli streams,
using an arbitrary large value for the compression type in the Zip local
file header. This only allows to read such archives, but not to produce
them, and, for now, support for brotli streams is kept Nightly-only,
until everything is pieced together and we're happy to ship it.
--HG--
extra : rebase_source : fa637251f460ad0d91d5f5bec392c6e59555e80d
2017-04-07 08:48:25 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2010-06-05 01:10:23 +04:00
|
|
|
default:
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-06-05 01:10:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mDoCRC) {
|
|
|
|
mCRC = crc32(mCRC, (const unsigned char *)buf, *aBytesRead);
|
|
|
|
if (verifyCRC && mCRC != mItem->CRC32()) return nullptr;
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
MOZ_WIN_MEM_TRY_CATCH(return nullptr)
|
2010-06-05 01:10:23 +04:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2015-10-20 14:32:47 +03:00
|
|
|
nsZipItemPtr_base::nsZipItemPtr_base(nsZipArchive *aZip, const char *aEntryName,
|
|
|
|
bool doCRC)
|
|
|
|
: mReturnBuf(nullptr), mReadlen(0) {
|
2010-06-05 01:10:23 +04:00
|
|
|
// make sure the ziparchive hangs around
|
|
|
|
mZipHandle = aZip->GetFD();
|
2010-11-11 23:13:48 +03:00
|
|
|
|
2010-06-05 01:10:23 +04:00
|
|
|
nsZipItem *item = aZip->GetItem(aEntryName);
|
|
|
|
if (!item) return;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t size = 0;
|
Bug 1355661 - Add support for brotli streams in Jar archives. r=aklotz
Modern compression algorithms are better than zlib both in terms of
space and time. The jar format, used for e.g. omni.ja, addons, etc.
could benefit from using such modern algorithms, but the format only
allows a limited set of compression algorithms.
However, the format in itself is flexible, in that it can be extended
with arbitrary compression algorithms. This breaks compatibility with
programs like unzip, obviously, but we've never promised the files
shipped with Firefox will always remain "valid" zips (which they already
aren't, but they currently work with most zip readers).
With this change, we allow those archives to contain brotli streams,
using an arbitrary large value for the compression type in the Zip local
file header. This only allows to read such archives, but not to produce
them, and, for now, support for brotli streams is kept Nightly-only,
until everything is pieced together and we're happy to ship it.
--HG--
extra : rebase_source : fa637251f460ad0d91d5f5bec392c6e59555e80d
2017-04-07 08:48:25 +03:00
|
|
|
bool compressed = (item->Compression() == DEFLATED);
|
|
|
|
#ifdef MOZ_JAR_BROTLI
|
|
|
|
compressed |= (item->Compression() == MOZ_JAR_BROTLI);
|
|
|
|
#endif
|
|
|
|
if (compressed) {
|
2010-06-05 01:10:23 +04:00
|
|
|
size = item->RealSize();
|
2015-11-04 00:36:32 +03:00
|
|
|
mAutoBuf = MakeUniqueFallible<uint8_t[]>(size);
|
2013-12-11 23:14:03 +04:00
|
|
|
if (!mAutoBuf) {
|
|
|
|
return;
|
|
|
|
}
|
2010-06-05 01:10:23 +04:00
|
|
|
}
|
|
|
|
|
2015-11-04 00:36:32 +03:00
|
|
|
nsZipCursor cursor(item, aZip, mAutoBuf.get(), size, doCRC);
|
2010-06-05 01:10:23 +04:00
|
|
|
mReturnBuf = cursor.Read(&mReadlen);
|
2011-06-03 00:59:04 +04:00
|
|
|
if (!mReturnBuf) {
|
2010-06-05 01:10:23 +04:00
|
|
|
return;
|
2011-06-03 00:59:04 +04:00
|
|
|
}
|
2010-06-05 01:10:23 +04:00
|
|
|
|
|
|
|
if (mReadlen != item->RealSize()) {
|
|
|
|
NS_ASSERTION(mReadlen == item->RealSize(), "nsZipCursor underflow");
|
2012-07-30 18:20:58 +04:00
|
|
|
mReturnBuf = nullptr;
|
2011-06-03 00:59:04 +04:00
|
|
|
return;
|
2010-06-05 01:10:23 +04:00
|
|
|
}
|
|
|
|
}
|