Bug 691847 - Always check bytecode version, r=Waldo
authorMichael Wu <mwu@mozilla.com>
Fri, 11 Nov 2011 19:15:19 -0800
changeset 80171 470d6053b749e2537dff21ed99882ab460b19b84
parent 80170 13590cb94eab1ed7e632bbd457ef3f9cb09298b3
child 80187 b914869ee1e03c4df1e31828c1a494cba32b045e
child 80239 d31f824210caca735722a99052c8818dbe98a642
child 81314 85ab4167c3f08348b5a6abe1f403abd22c0e1303
push id21469
push usermwu@mozilla.com
push dateSat, 12 Nov 2011 03:16:45 +0000
treeherdermozilla-central@470d6053b749 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs691847
milestone11.0a1
first release with
nightly linux32
470d6053b749 / 11.0a1 / 20111112031541 / files
nightly linux64
470d6053b749 / 11.0a1 / 20111112031541 / files
nightly mac
470d6053b749 / 11.0a1 / 20111112031541 / files
nightly win32
470d6053b749 / 11.0a1 / 20111112031541 / files
nightly win64
470d6053b749 / 11.0a1 / 20111112031541 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 691847 - Always check bytecode version, r=Waldo
js/src/jsxdrapi.cpp
js/src/jsxdrapi.h
--- a/js/src/jsxdrapi.cpp
+++ b/js/src/jsxdrapi.cpp
@@ -703,28 +703,33 @@ JS_XDRFunctionObject(JSXDRState *xdr, JS
 
 JS_PUBLIC_API(JSBool)
 JS_XDRScript(JSXDRState *xdr, JSScript **scriptp)
 {
     JS_ASSERT(!xdr->state);
 
     JSScript *script;
     uint32 magic;
+    uint32 bytecodeVer;
     if (xdr->mode == JSXDR_DECODE) {
         script = NULL;
         *scriptp = NULL;
     } else {
         script = *scriptp;
         magic = JSXDR_MAGIC_SCRIPT_CURRENT;
+        bytecodeVer = JSXDR_BYTECODE_VERSION;
     }
 
     if (!JS_XDRUint32(xdr, &magic))
         return false;
+    if (!JS_XDRUint32(xdr, &bytecodeVer))
+        return false;
 
-    if (magic != JSXDR_MAGIC_SCRIPT_CURRENT) {
+    if (magic != JSXDR_MAGIC_SCRIPT_CURRENT ||
+        bytecodeVer != JSXDR_BYTECODE_VERSION) {
         /* We do not provide binary compatibility with older scripts. */
         JS_ReportErrorNumber(xdr->cx, js_GetErrorMessage, NULL, JSMSG_BAD_SCRIPT_MAGIC);
         return false;
     }
 
     XDRScriptState state(xdr);
     if (!xdr->state)
         return false;
--- a/js/src/jsxdrapi.h
+++ b/js/src/jsxdrapi.h
@@ -209,26 +209,27 @@ JS_XDRFindClassById(JSXDRState *xdr, uin
 #define JSXDR_MAGIC_SCRIPT_4        0xdead0004
 #define JSXDR_MAGIC_SCRIPT_5        0xdead0005
 #define JSXDR_MAGIC_SCRIPT_6        0xdead0006
 #define JSXDR_MAGIC_SCRIPT_7        0xdead0007
 #define JSXDR_MAGIC_SCRIPT_8        0xdead0008
 #define JSXDR_MAGIC_SCRIPT_9        0xdead0009
 #define JSXDR_MAGIC_SCRIPT_10       0xdead000a
 #define JSXDR_MAGIC_SCRIPT_11       0xdead000b
-#define JSXDR_MAGIC_SCRIPT_CURRENT  JSXDR_MAGIC_SCRIPT_11
+#define JSXDR_MAGIC_SCRIPT_12       0xdead000c
+#define JSXDR_MAGIC_SCRIPT_CURRENT  JSXDR_MAGIC_SCRIPT_12
 
 /*
  * Bytecode version number. Increment the subtrahend 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.
+ * This version number is XDR'd near the front of xdr bytecode and
+ * aborts deserialization if there is a mismatch between the current
+ * and saved versions. If deserialization fails, the data should be
+ * invalidated if possible.
  */
 #define JSXDR_BYTECODE_VERSION      (0xb973c0de - 98)
 
 /*
  * Library-private functions.
  */
 extern JSBool
 js_XDRAtom(JSXDRState *xdr, JSAtom **atomp);