mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 590242 - Do not open omnijar 3x r=mwu, sr=bsmedberg, a=beltzner
This commit is contained in:
parent
e89c762801
commit
ade2669d85
@ -47,6 +47,7 @@
|
|||||||
#include "nsIConsoleService.h"
|
#include "nsIConsoleService.h"
|
||||||
#include "nsICryptoHash.h"
|
#include "nsICryptoHash.h"
|
||||||
#include "prprf.h"
|
#include "prprf.h"
|
||||||
|
#include "mozilla/Omnijar.h"
|
||||||
|
|
||||||
#ifdef XP_UNIX
|
#ifdef XP_UNIX
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -116,7 +117,8 @@ DeleteManifestEntry(nsHashKey* aKey, void* aData, void* closure)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The following initialization makes a guess of 10 entries per jarfile.
|
// The following initialization makes a guess of 10 entries per jarfile.
|
||||||
nsJAR::nsJAR(): mManifestData(nsnull, nsnull, DeleteManifestEntry, nsnull, 10),
|
nsJAR::nsJAR(): mZip(new nsZipArchive()),
|
||||||
|
mManifestData(nsnull, nsnull, DeleteManifestEntry, nsnull, 10),
|
||||||
mParsedManifest(PR_FALSE),
|
mParsedManifest(PR_FALSE),
|
||||||
mGlobalStatus(JAR_MANIFEST_NOT_PARSED),
|
mGlobalStatus(JAR_MANIFEST_NOT_PARSED),
|
||||||
mReleaseTime(PR_INTERVAL_NO_TIMEOUT),
|
mReleaseTime(PR_INTERVAL_NO_TIMEOUT),
|
||||||
@ -169,8 +171,18 @@ nsJAR::Open(nsIFile* zipFile)
|
|||||||
|
|
||||||
mLock = PR_NewLock();
|
mLock = PR_NewLock();
|
||||||
NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
|
NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
|
||||||
|
|
||||||
return mZip.OpenArchive(zipFile);
|
#ifdef MOZ_OMNIJAR
|
||||||
|
// The omnijar is special, it is opened early on and closed late
|
||||||
|
// this avoids reopening it
|
||||||
|
PRBool equals;
|
||||||
|
nsresult rv = zipFile->Equals(mozilla::OmnijarPath(), &equals);
|
||||||
|
if (NS_SUCCEEDED(rv) && equals) {
|
||||||
|
mZip = mozilla::OmnijarReader();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return mZip->OpenArchive(zipFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
@ -189,12 +201,12 @@ nsJAR::OpenInner(nsIZipReader *aZipReader, const char *aZipEntry)
|
|||||||
mOuterZipEntry.Assign(aZipEntry);
|
mOuterZipEntry.Assign(aZipEntry);
|
||||||
|
|
||||||
nsRefPtr<nsZipHandle> handle;
|
nsRefPtr<nsZipHandle> handle;
|
||||||
rv = nsZipHandle::Init(&static_cast<nsJAR*>(aZipReader)->mZip, aZipEntry,
|
rv = nsZipHandle::Init(static_cast<nsJAR*>(aZipReader)->mZip.get(), aZipEntry,
|
||||||
getter_AddRefs(handle));
|
getter_AddRefs(handle));
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
return rv;
|
return rv;
|
||||||
|
|
||||||
return mZip.OpenArchive(handle);
|
return mZip->OpenArchive(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
@ -219,13 +231,20 @@ nsJAR::Close()
|
|||||||
mTotalItemsInManifest = 0;
|
mTotalItemsInManifest = 0;
|
||||||
mOuterZipEntry.Truncate(0);
|
mOuterZipEntry.Truncate(0);
|
||||||
|
|
||||||
return mZip.CloseArchive();
|
#ifdef MOZ_OMNIJAR
|
||||||
|
if (mZip == mozilla::OmnijarReader()) {
|
||||||
|
mZip.forget();
|
||||||
|
mZip = new nsZipArchive();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return mZip->CloseArchive();
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJAR::Test(const char *aEntryName)
|
nsJAR::Test(const char *aEntryName)
|
||||||
{
|
{
|
||||||
return mZip.Test(aEntryName);
|
return mZip->Test(aEntryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
@ -239,7 +258,7 @@ nsJAR::Extract(const char *zipEntry, nsIFile* outFile)
|
|||||||
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(outFile, &rv);
|
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(outFile, &rv);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
nsZipItem *item = mZip.GetItem(zipEntry);
|
nsZipItem *item = mZip->GetItem(zipEntry);
|
||||||
NS_ENSURE_TRUE(item, NS_ERROR_FILE_TARGET_DOES_NOT_EXIST);
|
NS_ENSURE_TRUE(item, NS_ERROR_FILE_TARGET_DOES_NOT_EXIST);
|
||||||
|
|
||||||
// Remove existing file or directory so we set permissions correctly.
|
// Remove existing file or directory so we set permissions correctly.
|
||||||
@ -274,7 +293,7 @@ nsJAR::Extract(const char *zipEntry, nsIFile* outFile)
|
|||||||
rv = outFile->GetNativePath(path);
|
rv = outFile->GetNativePath(path);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
rv = mZip.ExtractFile(item, path.get(), fd);
|
rv = mZip->ExtractFile(item, path.get(), fd);
|
||||||
}
|
}
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
@ -288,7 +307,7 @@ nsJAR::Extract(const char *zipEntry, nsIFile* outFile)
|
|||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJAR::GetEntry(const char *aEntryName, nsIZipEntry* *result)
|
nsJAR::GetEntry(const char *aEntryName, nsIZipEntry* *result)
|
||||||
{
|
{
|
||||||
nsZipItem* zipItem = mZip.GetItem(aEntryName);
|
nsZipItem* zipItem = mZip->GetItem(aEntryName);
|
||||||
NS_ENSURE_TRUE(zipItem, NS_ERROR_FILE_TARGET_DOES_NOT_EXIST);
|
NS_ENSURE_TRUE(zipItem, NS_ERROR_FILE_TARGET_DOES_NOT_EXIST);
|
||||||
|
|
||||||
nsJARItem* jarItem = new nsJARItem(zipItem);
|
nsJARItem* jarItem = new nsJARItem(zipItem);
|
||||||
@ -301,7 +320,7 @@ nsJAR::GetEntry(const char *aEntryName, nsIZipEntry* *result)
|
|||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJAR::HasEntry(const nsACString &aEntryName, PRBool *result)
|
nsJAR::HasEntry(const nsACString &aEntryName, PRBool *result)
|
||||||
{
|
{
|
||||||
*result = mZip.GetItem(PromiseFlatCString(aEntryName).get()) != nsnull;
|
*result = mZip->GetItem(PromiseFlatCString(aEntryName).get()) != nsnull;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,7 +330,7 @@ nsJAR::FindEntries(const char *aPattern, nsIUTF8StringEnumerator **result)
|
|||||||
NS_ENSURE_ARG_POINTER(result);
|
NS_ENSURE_ARG_POINTER(result);
|
||||||
|
|
||||||
nsZipFind *find;
|
nsZipFind *find;
|
||||||
nsresult rv = mZip.FindInit(aPattern, &find);
|
nsresult rv = mZip->FindInit(aPattern, &find);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsIUTF8StringEnumerator *zipEnum = new nsJAREnumerator(find);
|
nsIUTF8StringEnumerator *zipEnum = new nsJAREnumerator(find);
|
||||||
@ -341,7 +360,7 @@ nsJAR::GetInputStreamWithSpec(const nsACString& aJarDirSpec,
|
|||||||
nsZipItem *item = nsnull;
|
nsZipItem *item = nsnull;
|
||||||
if (*aEntryName) {
|
if (*aEntryName) {
|
||||||
// First check if item exists in jar
|
// First check if item exists in jar
|
||||||
item = mZip.GetItem(aEntryName);
|
item = mZip->GetItem(aEntryName);
|
||||||
if (!item) return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST;
|
if (!item) return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST;
|
||||||
}
|
}
|
||||||
nsJARInputStream* jis = new nsJARInputStream();
|
nsJARInputStream* jis = new nsJARInputStream();
|
||||||
|
@ -133,7 +133,7 @@ class nsJAR : public nsIZipReader
|
|||||||
//-- Private data members
|
//-- Private data members
|
||||||
nsCOMPtr<nsIFile> mZipFile; // The zip/jar file on disk
|
nsCOMPtr<nsIFile> mZipFile; // The zip/jar file on disk
|
||||||
nsCString mOuterZipEntry; // The entry in the zip this zip is reading from
|
nsCString mOuterZipEntry; // The entry in the zip this zip is reading from
|
||||||
nsZipArchive mZip; // The underlying zip archive
|
nsAutoPtr<nsZipArchive> mZip; // The underlying zip archive
|
||||||
nsObjectHashtable mManifestData; // Stores metadata for each entry
|
nsObjectHashtable mManifestData; // Stores metadata for each entry
|
||||||
PRBool mParsedManifest; // True if manifest has been parsed
|
PRBool mParsedManifest; // True if manifest has been parsed
|
||||||
nsCOMPtr<nsIPrincipal> mPrincipal; // The entity which signed this file
|
nsCOMPtr<nsIPrincipal> mPrincipal; // The entity which signed this file
|
||||||
|
@ -87,8 +87,8 @@ nsJARInputStream::InitFile(nsJAR *aJar, nsZipItem *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Must keep handle to filepointer and mmap structure as long as we need access to the mmapped data
|
// Must keep handle to filepointer and mmap structure as long as we need access to the mmapped data
|
||||||
mFd = aJar->mZip.GetFD();
|
mFd = aJar->mZip->GetFD();
|
||||||
mZs.next_in = (Bytef *)aJar->mZip.GetData(item);
|
mZs.next_in = (Bytef *)aJar->mZip->GetData(item);
|
||||||
if (!mZs.next_in)
|
if (!mZs.next_in)
|
||||||
return NS_ERROR_FILE_CORRUPTED;
|
return NS_ERROR_FILE_CORRUPTED;
|
||||||
mZs.avail_in = item->Size();
|
mZs.avail_in = item->Size();
|
||||||
@ -147,7 +147,7 @@ nsJARInputStream::InitDirectory(nsJAR* aJar,
|
|||||||
}
|
}
|
||||||
nsCAutoString pattern = escDirName + NS_LITERAL_CSTRING("?*~") +
|
nsCAutoString pattern = escDirName + NS_LITERAL_CSTRING("?*~") +
|
||||||
escDirName + NS_LITERAL_CSTRING("?*/?*");
|
escDirName + NS_LITERAL_CSTRING("?*/?*");
|
||||||
rv = mJar->mZip.FindInit(pattern.get(), &find);
|
rv = mJar->mZip->FindInit(pattern.get(), &find);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
const char *name;
|
const char *name;
|
||||||
@ -341,7 +341,7 @@ nsJARInputStream::ReadDirectory(char* aBuffer, PRUint32 aCount, PRUint32 *aBytes
|
|||||||
|
|
||||||
const char * entryName = mArray[mArrPos].get();
|
const char * entryName = mArray[mArrPos].get();
|
||||||
PRUint32 entryNameLen = mArray[mArrPos].Length();
|
PRUint32 entryNameLen = mArray[mArrPos].Length();
|
||||||
nsZipItem* ze = mJar->mZip.GetItem(entryName);
|
nsZipItem* ze = mJar->mZip->GetItem(entryName);
|
||||||
NS_ENSURE_TRUE(ze, NS_ERROR_FILE_TARGET_DOES_NOT_EXIST);
|
NS_ENSURE_TRUE(ze, NS_ERROR_FILE_TARGET_DOES_NOT_EXIST);
|
||||||
|
|
||||||
// Last Modified Time
|
// Last Modified Time
|
||||||
|
Loading…
Reference in New Issue
Block a user