浏览代码

Update json.js

Lutz Roeder 2 月之前
父节点
当前提交
accba0cfd2
共有 2 个文件被更改,包括 9 次插入5 次删除
  1. 2 2
      source/flux.js
  2. 7 3
      source/json.js

+ 2 - 2
source/flux.js

@@ -31,10 +31,10 @@ flux.ModelFactory = class {
                 }
             } else if (obj === Object(obj)) {
                 if (obj.tag === 'backref' && obj.ref) {
-                    if (!root._backrefs[obj.ref - 1]) {
+                    if (!root._backrefs[obj.ref - 1n]) {
                         throw new flux.Error(`Invalid backref '${obj.ref}'.`);
                     }
-                    obj = root._backrefs[obj.ref - 1];
+                    obj = root._backrefs[obj.ref - 1n];
                 }
                 for (const key of Object.keys(obj)) {
                     if (obj !== root || key !== '_backrefs') {

+ 7 - 3
source/json.js

@@ -466,7 +466,11 @@ json.BinaryReader = class {
                 continue;
             }
             const start = position;
-            position = buffer.indexOf(0x00, start) + 1;
+            position = buffer.indexOf(0x00, start);
+            if (position === -1) {
+                throw new bson.Error('Missing string terminator.');
+            }
+            position += 1;
             const key = asciiDecoder.decode(buffer.subarray(start, position - 1));
             let value = null;
             switch (type) {
@@ -530,13 +534,13 @@ json.BinaryReader = class {
                 case 0x11: { // uint64
                     const start = position;
                     skip(8);
-                    value = Number(view.getBigUint64(start, true));
+                    value = view.getBigUint64(start, true);
                     break;
                 }
                 case 0x12: { // int64
                     const start = position;
                     skip(8);
-                    value = Number(view.getBigInt64(start, true));
+                    value = view.getBigInt64(start, true);
                     break;
                 }
                 default: {