protobufjs 7.5.9 → 7.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/light/protobuf.js +133 -73
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +3 -3
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/protobuf.js +62 -25
- package/dist/minimal/protobuf.js.map +1 -1
- package/dist/minimal/protobuf.min.js +3 -3
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +154 -80
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/ext/descriptor/index.js +7 -2
- package/index.d.ts +14 -4
- package/package.json +3 -3
- package/src/converter.js +13 -8
- package/src/encoder.js +8 -5
- package/src/enum.js +2 -2
- package/src/field.js +1 -1
- package/src/namespace.js +2 -0
- package/src/object.js +6 -6
- package/src/parse.js +19 -5
- package/src/root.js +14 -8
- package/src/type.js +9 -6
- package/src/util/minimal.js +32 -7
- package/src/util/patterns.js +0 -1
- package/src/util.js +4 -3
- package/src/wrappers.js +11 -7
- package/src/writer.js +11 -9
package/ext/descriptor/index.js
CHANGED
|
@@ -223,9 +223,14 @@ var unnamedMessageIndex = 0;
|
|
|
223
223
|
* @param {IDescriptorProto|Reader|Uint8Array} descriptor Descriptor
|
|
224
224
|
* @param {string} [edition="proto2"] The syntax or edition to use
|
|
225
225
|
* @param {boolean} [nested=false] Whether or not this is a nested object
|
|
226
|
+
* @param {number} [depth] Current nesting depth, defaults to `0`
|
|
226
227
|
* @returns {Type} Type instance
|
|
227
228
|
*/
|
|
228
|
-
Type.fromDescriptor = function fromDescriptor(descriptor, edition, nested) {
|
|
229
|
+
Type.fromDescriptor = function fromDescriptor(descriptor, edition, nested, depth) {
|
|
230
|
+
if (depth === undefined)
|
|
231
|
+
depth = 0;
|
|
232
|
+
if (depth > $protobuf.util.nestingLimit)
|
|
233
|
+
throw Error("max depth exceeded");
|
|
229
234
|
// Decode the descriptor message if specified as a buffer:
|
|
230
235
|
if (typeof descriptor.length === "number")
|
|
231
236
|
descriptor = exports.DescriptorProto.decode(descriptor);
|
|
@@ -252,7 +257,7 @@ Type.fromDescriptor = function fromDescriptor(descriptor, edition, nested) {
|
|
|
252
257
|
type.add(Field.fromDescriptor(descriptor.extension[i], edition, true));
|
|
253
258
|
/* Nested types */ if (descriptor.nestedType)
|
|
254
259
|
for (i = 0; i < descriptor.nestedType.length; ++i) {
|
|
255
|
-
type.add(Type.fromDescriptor(descriptor.nestedType[i], edition, true));
|
|
260
|
+
type.add(Type.fromDescriptor(descriptor.nestedType[i], edition, true, depth + 1));
|
|
256
261
|
if (descriptor.nestedType[i].options && descriptor.nestedType[i].options.mapEntry)
|
|
257
262
|
type.setOption("map_entry", true);
|
|
258
263
|
}
|
package/index.d.ts
CHANGED
|
@@ -1779,7 +1779,7 @@ export interface IConversionOptions {
|
|
|
1779
1779
|
|
|
1780
1780
|
/**
|
|
1781
1781
|
* Long conversion type.
|
|
1782
|
-
* Valid values are `String` and `Number` (the global types).
|
|
1782
|
+
* Valid values are `BigInt`, `String` and `Number` (the global types).
|
|
1783
1783
|
* Defaults to copy the present value, which is a possibly unsafe number without and a {@link Long} with a long library.
|
|
1784
1784
|
*/
|
|
1785
1785
|
longs?: Function;
|
|
@@ -2033,6 +2033,13 @@ export namespace util {
|
|
|
2033
2033
|
public length(): number;
|
|
2034
2034
|
}
|
|
2035
2035
|
|
|
2036
|
+
/**
|
|
2037
|
+
* Tests if the specified key can affect object prototypes.
|
|
2038
|
+
* @param key Key to test
|
|
2039
|
+
* @returns `true` if the key is unsafe
|
|
2040
|
+
*/
|
|
2041
|
+
function isUnsafeProperty(key: string): boolean;
|
|
2042
|
+
|
|
2036
2043
|
/** Whether running within node or not. */
|
|
2037
2044
|
let isNode: boolean;
|
|
2038
2045
|
|
|
@@ -2126,11 +2133,13 @@ export namespace util {
|
|
|
2126
2133
|
/**
|
|
2127
2134
|
* Merges the properties of the source object into the destination object.
|
|
2128
2135
|
* @param dst Destination object
|
|
2129
|
-
* @param src Source
|
|
2130
|
-
* @param [ifNotSet=false] Merges only if the key is not already set
|
|
2136
|
+
* @param src Source objects, optionally followed by an `ifNotSet` flag
|
|
2131
2137
|
* @returns Destination object
|
|
2132
2138
|
*/
|
|
2133
|
-
function merge(dst: { [k: string]: any }, src:
|
|
2139
|
+
function merge(dst: { [k: string]: any }, ...src: any[]): { [k: string]: any };
|
|
2140
|
+
|
|
2141
|
+
/** Schema declaration nesting limit. */
|
|
2142
|
+
let nestingLimit: number;
|
|
2134
2143
|
|
|
2135
2144
|
/** Recursion limit. */
|
|
2136
2145
|
let recursionLimit: number;
|
|
@@ -2484,6 +2493,7 @@ export namespace util {
|
|
|
2484
2493
|
* Requires a module only if available.
|
|
2485
2494
|
* @param moduleName Module to require
|
|
2486
2495
|
* @returns Required module if available and not empty, otherwise `null`
|
|
2496
|
+
* @deprecated Legacy optional require helper. Will be removed in a future release.
|
|
2487
2497
|
*/
|
|
2488
2498
|
function inquire(moduleName: string): object;
|
|
2489
2499
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "protobufjs",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.6.1",
|
|
4
4
|
"versionScheme": "~",
|
|
5
5
|
"description": "Protocol Buffers for JavaScript (& TypeScript).",
|
|
6
6
|
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@protobufjs/aspromise": "^1.1.2",
|
|
61
61
|
"@protobufjs/base64": "^1.1.2",
|
|
62
62
|
"@protobufjs/codegen": "^2.0.5",
|
|
63
|
-
"@protobufjs/eventemitter": "^1.1.
|
|
63
|
+
"@protobufjs/eventemitter": "^1.1.1",
|
|
64
64
|
"@protobufjs/fetch": "^1.1.1",
|
|
65
65
|
"@protobufjs/float": "^1.0.2",
|
|
66
66
|
"@protobufjs/inquire": "^1.1.2",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@protobufjs/pool": "^1.1.0",
|
|
69
69
|
"@protobufjs/utf8": "^1.1.1",
|
|
70
70
|
"@types/node": ">=13.7.0",
|
|
71
|
-
"long": "^5.
|
|
71
|
+
"long": "^5.3.2"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"benchmark": "^2.1.4",
|
package/src/converter.js
CHANGED
|
@@ -61,14 +61,14 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
|
|
|
61
61
|
("m%s=d%s|0", prop, prop);
|
|
62
62
|
break;
|
|
63
63
|
case "uint64":
|
|
64
|
+
case "fixed64":
|
|
64
65
|
isUnsigned = true;
|
|
65
66
|
// eslint-disable-next-line no-fallthrough
|
|
66
67
|
case "int64":
|
|
67
68
|
case "sint64":
|
|
68
|
-
case "fixed64":
|
|
69
69
|
case "sfixed64": gen
|
|
70
70
|
("if(util.Long)")
|
|
71
|
-
("
|
|
71
|
+
("m%s=util.Long.fromValue(d%s,%j)", prop, prop, isUnsigned)
|
|
72
72
|
("else if(typeof d%s===\"string\")", prop)
|
|
73
73
|
("m%s=parseInt(d%s,10)", prop, prop)
|
|
74
74
|
("else if(typeof d%s===\"number\")", prop)
|
|
@@ -172,7 +172,7 @@ function genValuePartial_toObject(gen, field, fieldIndex, prop) {
|
|
|
172
172
|
if (field.resolvedType instanceof Enum) gen
|
|
173
173
|
("d%s=o.enums===String?(types[%i].values[m%s]===undefined?m%s:types[%i].values[m%s]):m%s", prop, fieldIndex, prop, prop, fieldIndex, prop, prop);
|
|
174
174
|
else gen
|
|
175
|
-
("d%s=types[%i].toObject(m%s,o)", prop, fieldIndex, prop);
|
|
175
|
+
("d%s=types[%i].toObject(m%s,o,q+1)", prop, fieldIndex, prop);
|
|
176
176
|
} else {
|
|
177
177
|
var isUnsigned = false;
|
|
178
178
|
switch (field.type) {
|
|
@@ -181,13 +181,15 @@ function genValuePartial_toObject(gen, field, fieldIndex, prop) {
|
|
|
181
181
|
("d%s=o.json&&!isFinite(m%s)?String(m%s):m%s", prop, prop, prop, prop);
|
|
182
182
|
break;
|
|
183
183
|
case "uint64":
|
|
184
|
+
case "fixed64":
|
|
184
185
|
isUnsigned = true;
|
|
185
186
|
// eslint-disable-next-line no-fallthrough
|
|
186
187
|
case "int64":
|
|
187
188
|
case "sint64":
|
|
188
|
-
case "fixed64":
|
|
189
189
|
case "sfixed64": gen
|
|
190
|
-
("if(typeof
|
|
190
|
+
("if(typeof BigInt!==\"undefined\"&&o.longs===BigInt)")
|
|
191
|
+
("d%s=typeof m%s===\"number\"?BigInt(m%s):util.Long.fromBits(m%s.low>>>0,m%s.high>>>0,%j).toBigInt()", prop, prop, prop, prop, prop, isUnsigned)
|
|
192
|
+
("else if(typeof m%s===\"number\")", prop)
|
|
191
193
|
("d%s=o.longs===String?String(m%s):m%s", prop, prop, prop)
|
|
192
194
|
("else") // Long-like
|
|
193
195
|
("d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toNumber(%s):m%s", prop, prop, prop, prop, isUnsigned ? "true": "", prop);
|
|
@@ -214,9 +216,12 @@ converter.toObject = function toObject(mtype) {
|
|
|
214
216
|
var fields = mtype.fieldsArray.slice().sort(util.compareFieldsById);
|
|
215
217
|
if (!fields.length)
|
|
216
218
|
return util.codegen()("return {}");
|
|
217
|
-
var gen = util.codegen(["m", "o"], mtype.name + "$toObject")
|
|
219
|
+
var gen = util.codegen(["m", "o", "q"], mtype.name + "$toObject")
|
|
218
220
|
("if(!o)")
|
|
219
221
|
("o={}")
|
|
222
|
+
("if(q===undefined)q=0")
|
|
223
|
+
("if(q>util.recursionLimit)")
|
|
224
|
+
("throw Error(\"max depth exceeded\")")
|
|
220
225
|
("var d={}");
|
|
221
226
|
|
|
222
227
|
var repeatedFields = [],
|
|
@@ -255,9 +260,9 @@ converter.toObject = function toObject(mtype) {
|
|
|
255
260
|
else if (field.long) gen
|
|
256
261
|
("if(util.Long){")
|
|
257
262
|
("var n=new util.Long(%i,%i,%j)", field.typeDefault.low, field.typeDefault.high, field.typeDefault.unsigned)
|
|
258
|
-
("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():n", prop)
|
|
263
|
+
("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():typeof BigInt!==\"undefined\"&&o.longs===BigInt?n.toBigInt():n", prop)
|
|
259
264
|
("}else")
|
|
260
|
-
("d%s=o.longs===String?%j:%i", prop, field.typeDefault.toString(), field.typeDefault.toNumber());
|
|
265
|
+
("d%s=o.longs===String?%j:typeof BigInt!==\"undefined\"&&o.longs===BigInt?BigInt(%j):%i", prop, field.typeDefault.toString(), field.typeDefault.toString(), field.typeDefault.toNumber());
|
|
261
266
|
else if (field.bytes) {
|
|
262
267
|
var arrayDefault = Array.prototype.slice.call(field.typeDefault);
|
|
263
268
|
gen
|
package/src/encoder.js
CHANGED
|
@@ -16,8 +16,8 @@ var Enum = require("./enum"),
|
|
|
16
16
|
*/
|
|
17
17
|
function genTypePartial(gen, field, fieldIndex, ref) {
|
|
18
18
|
return field.delimited
|
|
19
|
-
? gen("types[%i].encode(%s,w.uint32(%i)).uint32(%i)", fieldIndex, ref, (field.id << 3 | 3) >>> 0, (field.id << 3 | 4) >>> 0)
|
|
20
|
-
: gen("types[%i].encode(%s,w.uint32(%i).fork()).ldelim()", fieldIndex, ref, (field.id << 3 | 2) >>> 0);
|
|
19
|
+
? gen("types[%i].encode(%s,w.uint32(%i),q+1).uint32(%i)", fieldIndex, ref, (field.id << 3 | 3) >>> 0, (field.id << 3 | 4) >>> 0)
|
|
20
|
+
: gen("types[%i].encode(%s,w.uint32(%i).fork(),q+1).ldelim()", fieldIndex, ref, (field.id << 3 | 2) >>> 0);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -27,9 +27,12 @@ function genTypePartial(gen, field, fieldIndex, ref) {
|
|
|
27
27
|
*/
|
|
28
28
|
function encoder(mtype) {
|
|
29
29
|
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
|
30
|
-
var gen = util.codegen(["m", "w"], mtype.name + "$encode")
|
|
30
|
+
var gen = util.codegen(["m", "w", "q"], mtype.name + "$encode")
|
|
31
31
|
("if(!w)")
|
|
32
|
-
("w=Writer.create()")
|
|
32
|
+
("w=Writer.create()")
|
|
33
|
+
("if(q===undefined)q=0")
|
|
34
|
+
("if(q>util.recursionLimit)")
|
|
35
|
+
("throw Error(\"max depth exceeded\")");
|
|
33
36
|
|
|
34
37
|
var i, ref;
|
|
35
38
|
|
|
@@ -50,7 +53,7 @@ function encoder(mtype) {
|
|
|
50
53
|
("for(var ks=Object.keys(%s),i=0;i<ks.length;++i){", ref)
|
|
51
54
|
("w.uint32(%i).fork().uint32(%i).%s(ks[i])", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[field.keyType], field.keyType);
|
|
52
55
|
if (wireType === undefined) gen
|
|
53
|
-
("types[%i].encode(%s[ks[i]],w.uint32(18).fork()).ldelim().ldelim()", index, ref); // can't be groups
|
|
56
|
+
("types[%i].encode(%s[ks[i]],w.uint32(18).fork(),q+1).ldelim().ldelim()", index, ref); // can't be groups
|
|
54
57
|
else gen
|
|
55
58
|
(".uint32(%i).%s(%s[ks[i]]).ldelim()", 16 | wireType, type, ref);
|
|
56
59
|
gen
|
package/src/enum.js
CHANGED
|
@@ -86,8 +86,8 @@ Enum.prototype._resolveFeatures = function _resolveFeatures(edition) {
|
|
|
86
86
|
ReflectionObject.prototype._resolveFeatures.call(this, edition);
|
|
87
87
|
|
|
88
88
|
Object.keys(this.values).forEach(key => {
|
|
89
|
-
var parentFeaturesCopy =
|
|
90
|
-
this._valuesFeatures[key] =
|
|
89
|
+
var parentFeaturesCopy = util.merge({}, this._features);
|
|
90
|
+
this._valuesFeatures[key] = util.merge(parentFeaturesCopy, this.valuesOptions && this.valuesOptions[key] && this.valuesOptions[key].features || {});
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
return this;
|
package/src/field.js
CHANGED
|
@@ -328,7 +328,7 @@ Field.prototype.resolve = function resolve() {
|
|
|
328
328
|
|
|
329
329
|
// convert to internal data type if necesssary
|
|
330
330
|
if (this.long) {
|
|
331
|
-
this.typeDefault = util.Long.fromNumber(this.typeDefault, this.type.
|
|
331
|
+
this.typeDefault = util.Long.fromNumber(this.typeDefault, this.type === "uint64" || this.type === "fixed64");
|
|
332
332
|
|
|
333
333
|
/* istanbul ignore else */
|
|
334
334
|
if (Object.freeze)
|
package/src/namespace.js
CHANGED
|
@@ -337,6 +337,8 @@ Namespace.prototype.define = function define(path, json) {
|
|
|
337
337
|
throw TypeError("illegal path");
|
|
338
338
|
if (path && path.length && path[0] === "")
|
|
339
339
|
throw Error("path must be relative");
|
|
340
|
+
if (path.length > util.recursionLimit)
|
|
341
|
+
throw Error("max depth exceeded");
|
|
340
342
|
|
|
341
343
|
var ptr = this;
|
|
342
344
|
while (path.length > 0) {
|
package/src/object.js
CHANGED
|
@@ -213,7 +213,7 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
|
|
|
213
213
|
throw new Error("Unknown edition for " + this.fullName);
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
var protoFeatures =
|
|
216
|
+
var protoFeatures = util.merge({}, this.options && this.options.features,
|
|
217
217
|
this._inferLegacyProtoFeatures(edition));
|
|
218
218
|
|
|
219
219
|
if (this._edition) {
|
|
@@ -228,7 +228,7 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
|
|
|
228
228
|
} else {
|
|
229
229
|
throw new Error("Unknown edition: " + edition);
|
|
230
230
|
}
|
|
231
|
-
this._features =
|
|
231
|
+
this._features = util.merge(defaults, protoFeatures);
|
|
232
232
|
this._featuresResolved = true;
|
|
233
233
|
return;
|
|
234
234
|
}
|
|
@@ -237,13 +237,13 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
|
|
|
237
237
|
// special-case it
|
|
238
238
|
/* istanbul ignore else */
|
|
239
239
|
if (this.partOf instanceof OneOf) {
|
|
240
|
-
var lexicalParentFeaturesCopy =
|
|
241
|
-
this._features =
|
|
240
|
+
var lexicalParentFeaturesCopy = util.merge({}, this.partOf._features);
|
|
241
|
+
this._features = util.merge(lexicalParentFeaturesCopy, protoFeatures);
|
|
242
242
|
} else if (this.declaringField) {
|
|
243
243
|
// Skip feature resolution of sister fields.
|
|
244
244
|
} else if (this.parent) {
|
|
245
|
-
var parentFeaturesCopy =
|
|
246
|
-
this._features =
|
|
245
|
+
var parentFeaturesCopy = util.merge({}, this.parent._features);
|
|
246
|
+
this._features = util.merge(parentFeaturesCopy, protoFeatures);
|
|
247
247
|
} else {
|
|
248
248
|
throw new Error("Unable to find a parent for " + this.fullName);
|
|
249
249
|
}
|
package/src/parse.js
CHANGED
|
@@ -302,7 +302,9 @@ function parse(source, root, options) {
|
|
|
302
302
|
|
|
303
303
|
|
|
304
304
|
function parseCommon(parent, token, depth) {
|
|
305
|
-
depth
|
|
305
|
+
if (depth === undefined)
|
|
306
|
+
depth = 0;
|
|
307
|
+
// depth is checked by dispatched functions
|
|
306
308
|
switch (token) {
|
|
307
309
|
|
|
308
310
|
case "option":
|
|
@@ -352,7 +354,10 @@ function parse(source, root, options) {
|
|
|
352
354
|
}
|
|
353
355
|
|
|
354
356
|
function parseType(parent, token, depth) {
|
|
355
|
-
depth
|
|
357
|
+
if (depth === undefined)
|
|
358
|
+
depth = 0;
|
|
359
|
+
if (depth > util.nestingLimit)
|
|
360
|
+
throw Error("max depth exceeded");
|
|
356
361
|
|
|
357
362
|
/* istanbul ignore if */
|
|
358
363
|
if (!nameRe.test(token = next()))
|
|
@@ -478,7 +483,10 @@ function parse(source, root, options) {
|
|
|
478
483
|
}
|
|
479
484
|
|
|
480
485
|
function parseGroup(parent, rule, depth) {
|
|
481
|
-
depth
|
|
486
|
+
if (depth === undefined)
|
|
487
|
+
depth = 0;
|
|
488
|
+
if (depth > util.nestingLimit)
|
|
489
|
+
throw Error("max depth exceeded");
|
|
482
490
|
if (edition >= 2023) {
|
|
483
491
|
throw illegal("group");
|
|
484
492
|
}
|
|
@@ -697,7 +705,10 @@ function parse(source, root, options) {
|
|
|
697
705
|
}
|
|
698
706
|
|
|
699
707
|
function parseOptionValue(parent, name, depth) {
|
|
700
|
-
depth
|
|
708
|
+
if (depth === undefined)
|
|
709
|
+
depth = 0;
|
|
710
|
+
if (depth > util.recursionLimit)
|
|
711
|
+
throw Error("max depth exceeded");
|
|
701
712
|
// { a: "foo" b { c: "bar" } }
|
|
702
713
|
if (skip("{", true)) {
|
|
703
714
|
var objectResult = {};
|
|
@@ -786,7 +797,10 @@ function parse(source, root, options) {
|
|
|
786
797
|
}
|
|
787
798
|
|
|
788
799
|
function parseService(parent, token, depth) {
|
|
789
|
-
depth
|
|
800
|
+
if (depth === undefined)
|
|
801
|
+
depth = 0;
|
|
802
|
+
if (depth > util.recursionLimit)
|
|
803
|
+
throw Error("max depth exceeded");
|
|
790
804
|
|
|
791
805
|
/* istanbul ignore if */
|
|
792
806
|
if (!nameRe.test(token = next()))
|
package/src/root.js
CHANGED
|
@@ -138,8 +138,12 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
// Processes a single file
|
|
141
|
-
function process(filename, source) {
|
|
141
|
+
function process(filename, source, depth) {
|
|
142
|
+
if (depth === undefined)
|
|
143
|
+
depth = 0;
|
|
142
144
|
try {
|
|
145
|
+
if (depth > util.recursionLimit)
|
|
146
|
+
throw Error("max depth exceeded");
|
|
143
147
|
if (util.isString(source) && source.charAt(0) === "{")
|
|
144
148
|
source = JSON.parse(source);
|
|
145
149
|
if (!util.isString(source))
|
|
@@ -152,11 +156,11 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
152
156
|
if (parsed.imports)
|
|
153
157
|
for (; i < parsed.imports.length; ++i)
|
|
154
158
|
if (resolved = getBundledFileName(parsed.imports[i]) || self.resolvePath(filename, parsed.imports[i]))
|
|
155
|
-
fetch(resolved);
|
|
159
|
+
fetch(resolved, false, depth + 1);
|
|
156
160
|
if (parsed.weakImports)
|
|
157
161
|
for (i = 0; i < parsed.weakImports.length; ++i)
|
|
158
162
|
if (resolved = getBundledFileName(parsed.weakImports[i]) || self.resolvePath(filename, parsed.weakImports[i]))
|
|
159
|
-
fetch(resolved, true);
|
|
163
|
+
fetch(resolved, true, depth + 1);
|
|
160
164
|
}
|
|
161
165
|
} catch (err) {
|
|
162
166
|
finish(err);
|
|
@@ -167,7 +171,9 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
167
171
|
}
|
|
168
172
|
|
|
169
173
|
// Fetches a single file
|
|
170
|
-
function fetch(filename, weak) {
|
|
174
|
+
function fetch(filename, weak, depth) {
|
|
175
|
+
if (depth === undefined)
|
|
176
|
+
depth = 0;
|
|
171
177
|
filename = getBundledFileName(filename) || filename;
|
|
172
178
|
|
|
173
179
|
// Skip if already loaded / attempted
|
|
@@ -179,12 +185,12 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
179
185
|
// Shortcut bundled definitions
|
|
180
186
|
if (filename in common) {
|
|
181
187
|
if (sync) {
|
|
182
|
-
process(filename, common[filename]);
|
|
188
|
+
process(filename, common[filename], depth);
|
|
183
189
|
} else {
|
|
184
190
|
++queued;
|
|
185
191
|
setTimeout(function() {
|
|
186
192
|
--queued;
|
|
187
|
-
process(filename, common[filename]);
|
|
193
|
+
process(filename, common[filename], depth);
|
|
188
194
|
});
|
|
189
195
|
}
|
|
190
196
|
return;
|
|
@@ -200,7 +206,7 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
200
206
|
finish(err);
|
|
201
207
|
return;
|
|
202
208
|
}
|
|
203
|
-
process(filename, source);
|
|
209
|
+
process(filename, source, depth);
|
|
204
210
|
} else {
|
|
205
211
|
++queued;
|
|
206
212
|
self.fetch(filename, function(err, source) {
|
|
@@ -217,7 +223,7 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
217
223
|
finish(null, self);
|
|
218
224
|
return;
|
|
219
225
|
}
|
|
220
|
-
process(filename, source);
|
|
226
|
+
process(filename, source, depth);
|
|
221
227
|
});
|
|
222
228
|
}
|
|
223
229
|
}
|
package/src/type.js
CHANGED
|
@@ -237,7 +237,10 @@ function clearCache(type) {
|
|
|
237
237
|
* @returns {Type} Created message type
|
|
238
238
|
*/
|
|
239
239
|
Type.fromJSON = function fromJSON(name, json, depth) {
|
|
240
|
-
depth
|
|
240
|
+
if (depth === undefined)
|
|
241
|
+
depth = 0;
|
|
242
|
+
if (depth > util.nestingLimit)
|
|
243
|
+
throw Error("max depth exceeded");
|
|
241
244
|
var type = new Type(name, json.options);
|
|
242
245
|
type.extensions = json.extensions;
|
|
243
246
|
type.reserved = json.reserved;
|
|
@@ -515,8 +518,8 @@ Type.prototype.setup = function setup() {
|
|
|
515
518
|
* @param {Writer} [writer] Writer to encode to
|
|
516
519
|
* @returns {Writer} writer
|
|
517
520
|
*/
|
|
518
|
-
Type.prototype.encode = function encode_setup(message, writer) {
|
|
519
|
-
return this.setup().encode(
|
|
521
|
+
Type.prototype.encode = function encode_setup(message, writer) { // eslint-disable-line no-unused-vars
|
|
522
|
+
return this.setup().encode.apply(this, arguments); // overrides this method
|
|
520
523
|
};
|
|
521
524
|
|
|
522
525
|
/**
|
|
@@ -580,7 +583,7 @@ Type.prototype.fromObject = function fromObject(object, depth) {
|
|
|
580
583
|
* Conversion options as used by {@link Type#toObject} and {@link Message.toObject}.
|
|
581
584
|
* @interface IConversionOptions
|
|
582
585
|
* @property {Function} [longs] Long conversion type.
|
|
583
|
-
* Valid values are `String` and `Number` (the global types).
|
|
586
|
+
* Valid values are `BigInt`, `String` and `Number` (the global types).
|
|
584
587
|
* Defaults to copy the present value, which is a possibly unsafe number without and a {@link Long} with a long library.
|
|
585
588
|
* @property {Function} [enums] Enum value conversion type.
|
|
586
589
|
* Only valid value is `String` (the global type).
|
|
@@ -601,8 +604,8 @@ Type.prototype.fromObject = function fromObject(object, depth) {
|
|
|
601
604
|
* @param {IConversionOptions} [options] Conversion options
|
|
602
605
|
* @returns {Object.<string,*>} Plain object
|
|
603
606
|
*/
|
|
604
|
-
Type.prototype.toObject = function toObject(message, options) {
|
|
605
|
-
return this.setup().toObject(
|
|
607
|
+
Type.prototype.toObject = function toObject(message, options) { // eslint-disable-line no-unused-vars
|
|
608
|
+
return this.setup().toObject.apply(this, arguments);
|
|
606
609
|
};
|
|
607
610
|
|
|
608
611
|
/**
|
package/src/util/minimal.js
CHANGED
|
@@ -25,6 +25,18 @@ util.pool = require("@protobufjs/pool");
|
|
|
25
25
|
// utility to work with the low and high bits of a 64 bit value
|
|
26
26
|
util.LongBits = require("./longbits");
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Tests if the specified key can affect object prototypes.
|
|
30
|
+
* @memberof util
|
|
31
|
+
* @param {string} key Key to test
|
|
32
|
+
* @returns {boolean} `true` if the key is unsafe
|
|
33
|
+
*/
|
|
34
|
+
function isUnsafeProperty(key) {
|
|
35
|
+
return key === "__proto__" || key === "prototype" || key === "constructor";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
util.isUnsafeProperty = isUnsafeProperty;
|
|
39
|
+
|
|
28
40
|
/**
|
|
29
41
|
* Whether running within node or not.
|
|
30
42
|
* @memberof util
|
|
@@ -238,26 +250,39 @@ util.longFromHash = function longFromHash(hash, unsigned) {
|
|
|
238
250
|
* Merges the properties of the source object into the destination object.
|
|
239
251
|
* @memberof util
|
|
240
252
|
* @param {Object.<string,*>} dst Destination object
|
|
241
|
-
* @param {Object.<string
|
|
242
|
-
* @param {boolean} [ifNotSet=false] Merges only if the key is not already set
|
|
253
|
+
* @param {...(Object.<string,*>|boolean)} src Source objects, optionally followed by an `ifNotSet` flag
|
|
243
254
|
* @returns {Object.<string,*>} Destination object
|
|
244
255
|
*/
|
|
245
|
-
function merge(dst
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
256
|
+
function merge(dst) { // used by converters
|
|
257
|
+
var ifNotSet = typeof arguments[arguments.length - 1] === "boolean",
|
|
258
|
+
limit = ifNotSet ? arguments.length - 1 : arguments.length;
|
|
259
|
+
ifNotSet = ifNotSet && arguments[arguments.length - 1];
|
|
260
|
+
for (var a = 1; a < limit; ++a) {
|
|
261
|
+
var src = arguments[a];
|
|
262
|
+
if (!src)
|
|
263
|
+
continue;
|
|
264
|
+
for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
|
|
265
|
+
if (!isUnsafeProperty(keys[i]) && (dst[keys[i]] === undefined || !ifNotSet))
|
|
249
266
|
dst[keys[i]] = src[keys[i]];
|
|
267
|
+
}
|
|
250
268
|
return dst;
|
|
251
269
|
}
|
|
252
270
|
|
|
253
271
|
util.merge = merge;
|
|
254
272
|
|
|
273
|
+
/**
|
|
274
|
+
* Schema declaration nesting limit.
|
|
275
|
+
* @memberof util
|
|
276
|
+
* @type {number}
|
|
277
|
+
*/
|
|
278
|
+
util.nestingLimit = 32; // protoc: MaxMessageDeclarationNestingDepth
|
|
279
|
+
|
|
255
280
|
/**
|
|
256
281
|
* Recursion limit.
|
|
257
282
|
* @memberof util
|
|
258
283
|
* @type {number}
|
|
259
284
|
*/
|
|
260
|
-
util.recursionLimit = 100;
|
|
285
|
+
util.recursionLimit = 100; // protoc: CodedInputStream::default_recursion_limit_
|
|
261
286
|
|
|
262
287
|
/**
|
|
263
288
|
* Makes a property safe for assignment as an own property.
|
package/src/util/patterns.js
CHANGED
|
@@ -5,4 +5,3 @@ var patterns = exports;
|
|
|
5
5
|
patterns.numberRe = /^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/;
|
|
6
6
|
patterns.typeRefRe = /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/;
|
|
7
7
|
patterns.reservedRe = /^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/;
|
|
8
|
-
patterns.unsafePropertyRe = /^(?:__proto__|prototype|constructor)$/;
|
package/src/util.js
CHANGED
|
@@ -16,8 +16,7 @@ util.fetch = require("@protobufjs/fetch");
|
|
|
16
16
|
util.path = require("@protobufjs/path");
|
|
17
17
|
util.patterns = require("./util/patterns");
|
|
18
18
|
|
|
19
|
-
var reservedRe = util.patterns.reservedRe
|
|
20
|
-
unsafePropertyRe = util.patterns.unsafePropertyRe;
|
|
19
|
+
var reservedRe = util.patterns.reservedRe;
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
22
|
* Node's fs module if available.
|
|
@@ -192,7 +191,7 @@ util.decorateEnum = function decorateEnum(object) {
|
|
|
192
191
|
util.setProperty = function setProperty(dst, path, value, ifNotSet) {
|
|
193
192
|
function setProp(dst, path, value) {
|
|
194
193
|
var part = path.shift();
|
|
195
|
-
if (
|
|
194
|
+
if (util.isUnsafeProperty(part))
|
|
196
195
|
return dst;
|
|
197
196
|
if (path.length > 0) {
|
|
198
197
|
dst[part] = setProp(dst[part] || {}, path, value);
|
|
@@ -213,6 +212,8 @@ util.setProperty = function setProperty(dst, path, value, ifNotSet) {
|
|
|
213
212
|
throw TypeError("path must be specified");
|
|
214
213
|
|
|
215
214
|
path = path.split(".");
|
|
215
|
+
if (path.length > util.recursionLimit)
|
|
216
|
+
throw Error("max depth exceeded");
|
|
216
217
|
return setProp(dst, path, value);
|
|
217
218
|
};
|
|
218
219
|
|
package/src/wrappers.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
var wrappers = exports;
|
|
9
9
|
|
|
10
|
-
var Message = require("./message")
|
|
10
|
+
var Message = require("./message"),
|
|
11
|
+
util = require("./util/minimal");
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* From object converter part of an {@link IWrapper}.
|
|
@@ -54,10 +55,9 @@ wrappers[".google.protobuf.Any"] = {
|
|
|
54
55
|
if (type_url.indexOf("/") === -1) {
|
|
55
56
|
type_url = "/" + type_url;
|
|
56
57
|
}
|
|
57
|
-
var nextDepth = depth === undefined ? 1 : depth + 1;
|
|
58
58
|
return this.create({
|
|
59
59
|
type_url: type_url,
|
|
60
|
-
value: type.encode(type.fromObject(object,
|
|
60
|
+
value: type.encode(type.fromObject(object, depth === undefined ? 1 : depth + 1)).finish()
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -65,7 +65,11 @@ wrappers[".google.protobuf.Any"] = {
|
|
|
65
65
|
return this.fromObject(object, depth);
|
|
66
66
|
},
|
|
67
67
|
|
|
68
|
-
toObject: function(message, options) {
|
|
68
|
+
toObject: function(message, options, depth) {
|
|
69
|
+
if (depth === undefined)
|
|
70
|
+
depth = 0;
|
|
71
|
+
if (depth > util.recursionLimit)
|
|
72
|
+
throw Error("max depth exceeded");
|
|
69
73
|
|
|
70
74
|
// Default prefix
|
|
71
75
|
var googleApi = "type.googleapis.com/";
|
|
@@ -81,12 +85,12 @@ wrappers[".google.protobuf.Any"] = {
|
|
|
81
85
|
var type = this.lookup(name);
|
|
82
86
|
/* istanbul ignore else */
|
|
83
87
|
if (type)
|
|
84
|
-
message = type.decode(message.value);
|
|
88
|
+
message = type.decode(message.value, undefined, undefined, depth + 1);
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
// wrap value if unmapped
|
|
88
92
|
if (!(message instanceof this.ctor) && message instanceof Message) {
|
|
89
|
-
var object = message.$type.toObject(message, options);
|
|
93
|
+
var object = message.$type.toObject(message, options, depth + 1);
|
|
90
94
|
var messageName = message.$type.fullName[0] === "." ?
|
|
91
95
|
message.$type.fullName.slice(1) : message.$type.fullName;
|
|
92
96
|
// Default to type.googleapis.com prefix if no prefix is used
|
|
@@ -98,6 +102,6 @@ wrappers[".google.protobuf.Any"] = {
|
|
|
98
102
|
return object;
|
|
99
103
|
}
|
|
100
104
|
|
|
101
|
-
return this.toObject(message, options);
|
|
105
|
+
return this.toObject(message, options, depth);
|
|
102
106
|
}
|
|
103
107
|
};
|
package/src/writer.js
CHANGED
|
@@ -225,7 +225,7 @@ Writer.prototype.uint32 = function write_uint32(value) {
|
|
|
225
225
|
* @returns {Writer} `this`
|
|
226
226
|
*/
|
|
227
227
|
Writer.prototype.int32 = function write_int32(value) {
|
|
228
|
-
return value < 0
|
|
228
|
+
return (value |= 0) < 0
|
|
229
229
|
? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec
|
|
230
230
|
: this.uint32(value);
|
|
231
231
|
};
|
|
@@ -240,16 +240,18 @@ Writer.prototype.sint32 = function write_sint32(value) {
|
|
|
240
240
|
};
|
|
241
241
|
|
|
242
242
|
function writeVarint64(val, buf, pos) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
243
|
+
var lo = val.lo,
|
|
244
|
+
hi = val.hi;
|
|
245
|
+
while (hi) {
|
|
246
|
+
buf[pos++] = lo & 127 | 128;
|
|
247
|
+
lo = (lo >>> 7 | hi << 25) >>> 0;
|
|
248
|
+
hi >>>= 7;
|
|
247
249
|
}
|
|
248
|
-
while (
|
|
249
|
-
buf[pos++] =
|
|
250
|
-
|
|
250
|
+
while (lo > 127) {
|
|
251
|
+
buf[pos++] = lo & 127 | 128;
|
|
252
|
+
lo = lo >>> 7;
|
|
251
253
|
}
|
|
252
|
-
buf[pos++] =
|
|
254
|
+
buf[pos++] = lo;
|
|
253
255
|
}
|
|
254
256
|
|
|
255
257
|
/**
|