protobufjs 7.5.6 → 7.5.8

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.
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v7.5.6 (c) 2016, daniel wirtz
3
- * compiled tue, 28 apr 2026 00:45:19 utc
2
+ * protobuf.js v7.5.8 (c) 2016, daniel wirtz
3
+ * compiled tue, 12 may 2026 09:39:59 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v7.5.6 (c) 2016, daniel wirtz
3
- * compiled tue, 28 apr 2026 00:45:19 utc
2
+ * protobuf.js v7.5.8 (c) 2016, daniel wirtz
3
+ * compiled tue, 12 may 2026 09:39:59 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
package/dist/protobuf.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v7.5.6 (c) 2016, daniel wirtz
3
- * compiled tue, 28 apr 2026 00:45:19 utc
2
+ * protobuf.js v7.5.8 (c) 2016, daniel wirtz
3
+ * compiled tue, 12 may 2026 09:39:59 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -3400,11 +3400,13 @@ var Type, // cyclic
3400
3400
  * @function
3401
3401
  * @param {string} name Namespace name
3402
3402
  * @param {Object.<string,*>} json JSON object
3403
+ * @param {number} [depth] Current nesting depth, defaults to `0`
3403
3404
  * @returns {Namespace} Created namespace
3404
3405
  * @throws {TypeError} If arguments are invalid
3405
3406
  */
3406
- Namespace.fromJSON = function fromJSON(name, json) {
3407
- return new Namespace(name, json.options).addJSON(json.nested);
3407
+ Namespace.fromJSON = function fromJSON(name, json, depth) {
3408
+ depth = util.checkDepth(depth);
3409
+ return new Namespace(name, json.options).addJSON(json.nested, depth);
3408
3410
  };
3409
3411
 
3410
3412
  /**
@@ -3562,9 +3564,11 @@ Namespace.prototype.toJSON = function toJSON(toJSONOptions) {
3562
3564
  /**
3563
3565
  * Adds nested objects to this namespace from nested object descriptors.
3564
3566
  * @param {Object.<string,AnyNestedObject>} nestedJson Any nested object descriptors
3567
+ * @param {number} [depth] Current nesting depth, defaults to `0`
3565
3568
  * @returns {Namespace} `this`
3566
3569
  */
3567
- Namespace.prototype.addJSON = function addJSON(nestedJson) {
3570
+ Namespace.prototype.addJSON = function addJSON(nestedJson, depth) {
3571
+ depth = util.checkDepth(depth);
3568
3572
  var ns = this;
3569
3573
  /* istanbul ignore else */
3570
3574
  if (nestedJson) {
@@ -3579,7 +3583,7 @@ Namespace.prototype.addJSON = function addJSON(nestedJson) {
3579
3583
  ? Service.fromJSON
3580
3584
  : nested.id !== undefined
3581
3585
  ? Field.fromJSON
3582
- : Namespace.fromJSON )(names[i], nested)
3586
+ : Namespace.fromJSON )(names[i], nested, depth + 1)
3583
3587
  );
3584
3588
  }
3585
3589
  }
@@ -3837,8 +3841,10 @@ Namespace.prototype._lookupImpl = function lookup(path, flatPath) {
3837
3841
  // Otherwise try each nested namespace
3838
3842
  } else {
3839
3843
  for (var i = 0; i < this.nestedArray.length; ++i)
3840
- if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath)))
3844
+ if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath))) {
3841
3845
  exact = found;
3846
+ break;
3847
+ }
3842
3848
  }
3843
3849
 
3844
3850
  // Set this even when null, so that when we walk up the tree we can quickly bail on repeated checks back down.
@@ -4832,7 +4838,8 @@ function parse(source, root, options) {
4832
4838
  }
4833
4839
 
4834
4840
 
4835
- function parseCommon(parent, token) {
4841
+ function parseCommon(parent, token, depth) {
4842
+ depth = util.checkDepth(depth);
4836
4843
  switch (token) {
4837
4844
 
4838
4845
  case "option":
@@ -4841,7 +4848,7 @@ function parse(source, root, options) {
4841
4848
  return true;
4842
4849
 
4843
4850
  case "message":
4844
- parseType(parent, token);
4851
+ parseType(parent, token, depth + 1);
4845
4852
  return true;
4846
4853
 
4847
4854
  case "enum":
@@ -4849,11 +4856,11 @@ function parse(source, root, options) {
4849
4856
  return true;
4850
4857
 
4851
4858
  case "service":
4852
- parseService(parent, token);
4859
+ parseService(parent, token, depth + 1);
4853
4860
  return true;
4854
4861
 
4855
4862
  case "extend":
4856
- parseExtension(parent, token);
4863
+ parseExtension(parent, token, depth);
4857
4864
  return true;
4858
4865
  }
4859
4866
  return false;
@@ -4881,7 +4888,8 @@ function parse(source, root, options) {
4881
4888
  }
4882
4889
  }
4883
4890
 
4884
- function parseType(parent, token) {
4891
+ function parseType(parent, token, depth) {
4892
+ depth = util.checkDepth(depth);
4885
4893
 
4886
4894
  /* istanbul ignore if */
4887
4895
  if (!nameRe.test(token = next()))
@@ -4889,7 +4897,7 @@ function parse(source, root, options) {
4889
4897
 
4890
4898
  var type = new Type(token);
4891
4899
  ifBlock(type, function parseType_block(token) {
4892
- if (parseCommon(type, token))
4900
+ if (parseCommon(type, token, depth))
4893
4901
  return;
4894
4902
 
4895
4903
  switch (token) {
@@ -4903,22 +4911,22 @@ function parse(source, root, options) {
4903
4911
  throw illegal(token);
4904
4912
  /* eslint-disable no-fallthrough */
4905
4913
  case "repeated":
4906
- parseField(type, token);
4914
+ parseField(type, token, undefined, depth + 1);
4907
4915
  break;
4908
4916
 
4909
4917
  case "optional":
4910
4918
  /* istanbul ignore if */
4911
4919
  if (edition === "proto3") {
4912
- parseField(type, "proto3_optional");
4920
+ parseField(type, "proto3_optional", undefined, depth + 1);
4913
4921
  } else if (edition !== "proto2") {
4914
4922
  throw illegal(token);
4915
4923
  } else {
4916
- parseField(type, "optional");
4924
+ parseField(type, "optional", undefined, depth + 1);
4917
4925
  }
4918
4926
  break;
4919
4927
 
4920
4928
  case "oneof":
4921
- parseOneOf(type, token);
4929
+ parseOneOf(type, token, depth + 1);
4922
4930
  break;
4923
4931
 
4924
4932
  case "extensions":
@@ -4936,7 +4944,7 @@ function parse(source, root, options) {
4936
4944
  }
4937
4945
 
4938
4946
  push(token);
4939
- parseField(type, "optional");
4947
+ parseField(type, "optional", undefined, depth + 1);
4940
4948
  break;
4941
4949
  }
4942
4950
  });
@@ -4946,10 +4954,10 @@ function parse(source, root, options) {
4946
4954
  }
4947
4955
  }
4948
4956
 
4949
- function parseField(parent, rule, extend) {
4957
+ function parseField(parent, rule, extend, depth) {
4950
4958
  var type = next();
4951
4959
  if (type === "group") {
4952
- parseGroup(parent, rule);
4960
+ parseGroup(parent, rule, depth);
4953
4961
  return;
4954
4962
  }
4955
4963
  // Type names can consume multiple tokens, in multiple variants:
@@ -5006,7 +5014,8 @@ function parse(source, root, options) {
5006
5014
  }
5007
5015
  }
5008
5016
 
5009
- function parseGroup(parent, rule) {
5017
+ function parseGroup(parent, rule, depth) {
5018
+ depth = util.checkDepth(depth);
5010
5019
  if (edition >= 2023) {
5011
5020
  throw illegal("group");
5012
5021
  }
@@ -5034,20 +5043,20 @@ function parse(source, root, options) {
5034
5043
  break;
5035
5044
  case "required":
5036
5045
  case "repeated":
5037
- parseField(type, token);
5046
+ parseField(type, token, undefined, depth + 1);
5038
5047
  break;
5039
5048
 
5040
5049
  case "optional":
5041
5050
  /* istanbul ignore if */
5042
5051
  if (edition === "proto3") {
5043
- parseField(type, "proto3_optional");
5052
+ parseField(type, "proto3_optional", undefined, depth + 1);
5044
5053
  } else {
5045
- parseField(type, "optional");
5054
+ parseField(type, "optional", undefined, depth + 1);
5046
5055
  }
5047
5056
  break;
5048
5057
 
5049
5058
  case "message":
5050
- parseType(type, token);
5059
+ parseType(type, token, depth + 1);
5051
5060
  break;
5052
5061
 
5053
5062
  case "enum":
@@ -5106,7 +5115,7 @@ function parse(source, root, options) {
5106
5115
  parent.add(field);
5107
5116
  }
5108
5117
 
5109
- function parseOneOf(parent, token) {
5118
+ function parseOneOf(parent, token, depth) {
5110
5119
 
5111
5120
  /* istanbul ignore if */
5112
5121
  if (!nameRe.test(token = next()))
@@ -5119,7 +5128,7 @@ function parse(source, root, options) {
5119
5128
  skip(";");
5120
5129
  } else {
5121
5130
  push(token);
5122
- parseField(oneof, "optional");
5131
+ parseField(oneof, "optional", undefined, depth);
5123
5132
  }
5124
5133
  });
5125
5134
  parent.add(oneof);
@@ -5224,7 +5233,8 @@ function parse(source, root, options) {
5224
5233
  setParsedOption(parent, option, optionValue, propName);
5225
5234
  }
5226
5235
 
5227
- function parseOptionValue(parent, name) {
5236
+ function parseOptionValue(parent, name, depth) {
5237
+ depth = util.checkDepth(depth);
5228
5238
  // { a: "foo" b { c: "bar" } }
5229
5239
  if (skip("{", true)) {
5230
5240
  var objectResult = {};
@@ -5247,7 +5257,7 @@ function parse(source, root, options) {
5247
5257
  // option (my_option) = {
5248
5258
  // repeated_value: [ "foo", "bar" ]
5249
5259
  // };
5250
- value = parseOptionValue(parent, name + "." + token);
5260
+ value = parseOptionValue(parent, name + "." + token, depth + 1);
5251
5261
  } else if (peek() === "[") {
5252
5262
  value = [];
5253
5263
  var lastValue;
@@ -5312,7 +5322,8 @@ function parse(source, root, options) {
5312
5322
  return parent;
5313
5323
  }
5314
5324
 
5315
- function parseService(parent, token) {
5325
+ function parseService(parent, token, depth) {
5326
+ depth = util.checkDepth(depth);
5316
5327
 
5317
5328
  /* istanbul ignore if */
5318
5329
  if (!nameRe.test(token = next()))
@@ -5320,7 +5331,7 @@ function parse(source, root, options) {
5320
5331
 
5321
5332
  var service = new Service(token);
5322
5333
  ifBlock(service, function parseService_block(token) {
5323
- if (parseCommon(service, token)) {
5334
+ if (parseCommon(service, token, depth)) {
5324
5335
  return;
5325
5336
  }
5326
5337
 
@@ -5386,7 +5397,7 @@ function parse(source, root, options) {
5386
5397
  parent.add(method);
5387
5398
  }
5388
5399
 
5389
- function parseExtension(parent, token) {
5400
+ function parseExtension(parent, token, depth) {
5390
5401
 
5391
5402
  /* istanbul ignore if */
5392
5403
  if (!typeRefRe.test(token = next()))
@@ -5398,15 +5409,15 @@ function parse(source, root, options) {
5398
5409
 
5399
5410
  case "required":
5400
5411
  case "repeated":
5401
- parseField(parent, token, reference);
5412
+ parseField(parent, token, reference, depth + 1);
5402
5413
  break;
5403
5414
 
5404
5415
  case "optional":
5405
5416
  /* istanbul ignore if */
5406
5417
  if (edition === "proto3") {
5407
- parseField(parent, "proto3_optional", reference);
5418
+ parseField(parent, "proto3_optional", reference, depth + 1);
5408
5419
  } else {
5409
- parseField(parent, "optional", reference);
5420
+ parseField(parent, "optional", reference, depth + 1);
5410
5421
  }
5411
5422
  break;
5412
5423
 
@@ -5415,7 +5426,7 @@ function parse(source, root, options) {
5415
5426
  if (edition === "proto2" || !typeRefRe.test(token))
5416
5427
  throw illegal(token);
5417
5428
  push(token);
5418
- parseField(parent, "optional", reference);
5429
+ parseField(parent, "optional", reference, depth + 1);
5419
5430
  break;
5420
5431
  }
5421
5432
  });
@@ -5467,7 +5478,7 @@ function parse(source, root, options) {
5467
5478
  default:
5468
5479
 
5469
5480
  /* istanbul ignore else */
5470
- if (parseCommon(ptr, token)) {
5481
+ if (parseCommon(ptr, token, 0)) {
5471
5482
  head = false;
5472
5483
  continue;
5473
5484
  }
@@ -6039,14 +6050,16 @@ function Root(options) {
6039
6050
  * Loads a namespace descriptor into a root namespace.
6040
6051
  * @param {INamespace} json Namespace descriptor
6041
6052
  * @param {Root} [root] Root namespace, defaults to create a new one if omitted
6053
+ * @param {number} [depth] Current nesting depth, defaults to `0`
6042
6054
  * @returns {Root} Root namespace
6043
6055
  */
6044
- Root.fromJSON = function fromJSON(json, root) {
6056
+ Root.fromJSON = function fromJSON(json, root, depth) {
6057
+ depth = util.checkDepth(depth);
6045
6058
  if (!root)
6046
6059
  root = new Root();
6047
6060
  if (json.options)
6048
6061
  root.setOptions(json.options);
6049
- return root.addJSON(json.nested).resolveAll();
6062
+ return root.addJSON(json.nested, depth).resolveAll();
6050
6063
  };
6051
6064
 
6052
6065
  /**
@@ -6640,17 +6653,19 @@ function Service(name, options) {
6640
6653
  * Constructs a service from a service descriptor.
6641
6654
  * @param {string} name Service name
6642
6655
  * @param {IService} json Service descriptor
6656
+ * @param {number} [depth] Current nesting depth, defaults to `0`
6643
6657
  * @returns {Service} Created service
6644
6658
  * @throws {TypeError} If arguments are invalid
6645
6659
  */
6646
- Service.fromJSON = function fromJSON(name, json) {
6660
+ Service.fromJSON = function fromJSON(name, json, depth) {
6661
+ depth = util.checkDepth(depth);
6647
6662
  var service = new Service(name, json.options);
6648
6663
  /* istanbul ignore else */
6649
6664
  if (json.methods)
6650
6665
  for (var names = Object.keys(json.methods), i = 0; i < names.length; ++i)
6651
6666
  service.add(Method.fromJSON(names[i], json.methods[names[i]]));
6652
6667
  if (json.nested)
6653
- service.addJSON(json.nested);
6668
+ service.addJSON(json.nested, depth);
6654
6669
  if (json.edition)
6655
6670
  service._edition = json.edition;
6656
6671
  service.comment = json.comment;
@@ -7438,9 +7453,11 @@ function clearCache(type) {
7438
7453
  * Creates a message type from a message type descriptor.
7439
7454
  * @param {string} name Message name
7440
7455
  * @param {IType} json Message type descriptor
7456
+ * @param {number} [depth] Current nesting depth, defaults to `0`
7441
7457
  * @returns {Type} Created message type
7442
7458
  */
7443
- Type.fromJSON = function fromJSON(name, json) {
7459
+ Type.fromJSON = function fromJSON(name, json, depth) {
7460
+ depth = util.checkDepth(depth);
7444
7461
  var type = new Type(name, json.options);
7445
7462
  type.extensions = json.extensions;
7446
7463
  type.reserved = json.reserved;
@@ -7467,7 +7484,7 @@ Type.fromJSON = function fromJSON(name, json) {
7467
7484
  ? Enum.fromJSON
7468
7485
  : nested.methods !== undefined
7469
7486
  ? Service.fromJSON
7470
- : Namespace.fromJSON )(names[i], nested)
7487
+ : Namespace.fromJSON )(names[i], nested, depth + 1)
7471
7488
  );
7472
7489
  }
7473
7490
  if (json.extensions && json.extensions.length)
@@ -8055,6 +8072,20 @@ var reservedRe = util.patterns.reservedRe,
8055
8072
  */
8056
8073
  util.fs = util.inquire("fs");
8057
8074
 
8075
+ /**
8076
+ * Checks a recursion depth.
8077
+ * @param {number|undefined} depth Depth of recursion
8078
+ * @returns {number} Depth of recursion
8079
+ * @throws {Error} If depth exceeds util.recursionLimit
8080
+ */
8081
+ util.checkDepth = function checkDepth(depth) {
8082
+ if (depth === undefined)
8083
+ depth = 0;
8084
+ if (depth > util.recursionLimit)
8085
+ throw Error("max depth exceeded");
8086
+ return depth;
8087
+ };
8088
+
8058
8089
  /**
8059
8090
  * Converts an object's values to an array.
8060
8091
  * @param {Object.<string,*>} object Object to convert