Fix lack of XPC.mfasl versioning via separate JS bytecode version (350787, r=mrbkap/dbaron/jst).

This commit is contained in:
brendan%mozilla.org 2006-09-05 22:53:47 +00:00
Родитель d557e3ec85
Коммит 555a781970
6 изменённых файлов: 45 добавлений и 17 удалений

Просмотреть файл

@ -127,9 +127,10 @@ NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult);
const char XUL_FASTLOAD_FILE_BASENAME[] = "XUL";
// Increase the subtractor when changing version, say when changing the
// (opaque to FastLoad code) format of JS script, function, regexp, etc.
// XDR serializations.
#define XUL_FASTLOAD_FILE_VERSION (0xfeedbeef - 18)
// (opaque to XPCOM FastLoad code) format of XUL-specific XDR serializations.
// See also JSXDR_BYTECODE_VERSION in jsxdrapi.h, which tracks incompatible JS
// bytecode version changes.
#define XUL_FASTLOAD_FILE_VERSION (0xfeedbeef - 20)
#define XUL_SERIALIZATION_BUFFER_SIZE (64 * 1024)
#define XUL_DESERIALIZATION_BUFFER_SIZE (8 * 1024)

Просмотреть файл

@ -72,6 +72,8 @@
#include "nsDataHashtable.h"
#include "nsAppDirectoryServiceDefs.h"
#include "jsxdrapi.h"
struct CacheScriptEntry
{
PRUint32 mScriptTypeID; // the script language ID.
@ -907,12 +909,16 @@ nsXULPrototypeCache::StartFastLoad(nsIURI* aURI)
// Get the XUL fastload file version number, which should be
// decremented whenever the XUL-specific file format changes
// (see public/nsIXULPrototypeCache.h for the #define).
PRUint32 version;
rv = objectInput->Read32(&version);
PRUint32 xulFastLoadVersion, jsByteCodeVersion;
rv = objectInput->Read32(&xulFastLoadVersion);
rv |= objectInput->Read32(&jsByteCodeVersion);
if (NS_SUCCEEDED(rv)) {
if (version != XUL_FASTLOAD_FILE_VERSION) {
if (xulFastLoadVersion != XUL_FASTLOAD_FILE_VERSION ||
jsByteCodeVersion != JSXDR_BYTECODE_VERSION) {
#ifdef DEBUG
printf("bad FastLoad file version\n");
printf((xulFastLoadVersion != XUL_FASTLOAD_FILE_VERSION)
? "bad FastLoad file version\n"
: "bad JS bytecode version\n");
#endif
rv = NS_ERROR_UNEXPECTED;
} else {
@ -962,6 +968,7 @@ nsXULPrototypeCache::StartFastLoad(nsIURI* aURI)
getter_AddRefs(objectOutput));
if (NS_SUCCEEDED(rv)) {
rv = objectOutput->Write32(XUL_FASTLOAD_FILE_VERSION);
rv |= objectOutput->Write32(JSXDR_BYTECODE_VERSION);
rv |= objectOutput->WriteStringZ(chromePath.get());
rv |= objectOutput->WriteStringZ(locale.get());
}

Просмотреть файл

@ -351,12 +351,7 @@ nsXULPrototypeDocument::Read(nsIObjectInputStream* aStream)
{
nsresult rv;
PRUint32 version;
rv = aStream->Read32(&version);
if (version != XUL_FASTLOAD_FILE_VERSION)
return NS_ERROR_FAILURE;
rv |= aStream->ReadObject(PR_TRUE, getter_AddRefs(mURI));
rv = aStream->ReadObject(PR_TRUE, getter_AddRefs(mURI));
PRUint32 referenceCount;
nsCOMPtr<nsIURI> referenceURI;
@ -479,9 +474,7 @@ nsXULPrototypeDocument::Write(nsIObjectOutputStream* aStream)
{
nsresult rv;
rv = aStream->Write32(XUL_FASTLOAD_FILE_VERSION);
rv |= aStream->WriteCompoundObject(mURI, NS_GET_IID(nsIURI), PR_TRUE);
rv = aStream->WriteCompoundObject(mURI, NS_GET_IID(nsIURI), PR_TRUE);
PRUint32 referenceCount;
nsCOMPtr<nsIURI> referenceURI;

Просмотреть файл

@ -1,4 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sw=4 et tw=78:
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
@ -190,6 +191,17 @@ JS_XDRFindClassById(JSXDRState *xdr, uint32 id);
#define JSXDR_MAGIC_SCRIPT_5 0xdead0005
#define JSXDR_MAGIC_SCRIPT_CURRENT JSXDR_MAGIC_SCRIPT_5
/*
* Bytecode version number. Decrement the second term whenever JS bytecode
* changes incompatibly.
*
* This version number should be XDR'ed once near the front of any file or
* larger storage unit containing XDR'ed bytecode and other data, and checked
* before deserialization of bytecode. If the saved version does not match
* the current version, abort deserialization and invalidate the file.
*/
#define JSXDR_BYTECODE_VERSION (0xb973c0de - 0)
/*
* Library-private functions.
*/

Просмотреть файл

@ -783,6 +783,16 @@ mozJSComponentLoader::StartFastLoad(nsIFastLoadService *flSvc)
}
}
}
if (NS_SUCCEEDED(rv)) {
/* Get the JS bytecode version number and validate it. */
PRUint32 version;
rv = mFastLoadInput->Read32(&version);
if (NS_SUCCEEDED(rv) && version != JSXDR_BYTECODE_VERSION) {
LOG(("Bad JS bytecode version\n"));
rv = NS_ERROR_UNEXPECTED;
}
}
}
if (NS_FAILED(rv)) {
LOG(("Invalid fastload file detected, removing it\n"));
@ -807,6 +817,10 @@ mozJSComponentLoader::StartFastLoad(nsIFastLoadService *flSvc)
rv = flSvc->NewOutputStream(output,
getter_AddRefs(mFastLoadOutput));
if (NS_SUCCEEDED(rv))
rv = mFastLoadOutput->Write32(JSXDR_BYTECODE_VERSION);
if (NS_FAILED(rv)) {
LOG(("Fatal error, could not create fastload file\n"));

Просмотреть файл

@ -141,7 +141,8 @@ typedef PRUint32 NSFastLoadOID; // nsFastLoadFooter::mObjectMap index
#define MFL_FILE_VERSION_0 0
#define MFL_FILE_VERSION_1 1000
#define MFL_FILE_VERSION 4 // fix to note singletons in object map
#define MFL_FILE_VERSION 5 // rev'ed to defend against unversioned
// XPCOM JS component fastload files
/**
* Compute Fletcher's 16-bit checksum over aLength bytes starting at aBuffer,