protobufjs 7.5.7 → 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.7 (c) 2016, daniel wirtz
3
- * compiled sat, 09 may 2026 05:45:39 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.7 (c) 2016, daniel wirtz
3
- * compiled sat, 09 may 2026 05:45:40 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.7 (c) 2016, daniel wirtz
3
- * compiled sat, 09 may 2026 05:45:39 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
  }
@@ -4834,7 +4838,8 @@ function parse(source, root, options) {
4834
4838
  }
4835
4839
 
4836
4840
 
4837
- function parseCommon(parent, token) {
4841
+ function parseCommon(parent, token, depth) {
4842
+ depth = util.checkDepth(depth);
4838
4843
  switch (token) {
4839
4844
 
4840
4845
  case "option":
@@ -4843,7 +4848,7 @@ function parse(source, root, options) {
4843
4848
  return true;
4844
4849
 
4845
4850
  case "message":
4846
- parseType(parent, token);
4851
+ parseType(parent, token, depth + 1);
4847
4852
  return true;
4848
4853
 
4849
4854
  case "enum":
@@ -4851,11 +4856,11 @@ function parse(source, root, options) {
4851
4856
  return true;
4852
4857
 
4853
4858
  case "service":
4854
- parseService(parent, token);
4859
+ parseService(parent, token, depth + 1);
4855
4860
  return true;
4856
4861
 
4857
4862
  case "extend":
4858
- parseExtension(parent, token);
4863
+ parseExtension(parent, token, depth);
4859
4864
  return true;
4860
4865
  }
4861
4866
  return false;
@@ -4883,7 +4888,8 @@ function parse(source, root, options) {
4883
4888
  }
4884
4889
  }
4885
4890
 
4886
- function parseType(parent, token) {
4891
+ function parseType(parent, token, depth) {
4892
+ depth = util.checkDepth(depth);
4887
4893
 
4888
4894
  /* istanbul ignore if */
4889
4895
  if (!nameRe.test(token = next()))
@@ -4891,7 +4897,7 @@ function parse(source, root, options) {
4891
4897
 
4892
4898
  var type = new Type(token);
4893
4899
  ifBlock(type, function parseType_block(token) {
4894
- if (parseCommon(type, token))
4900
+ if (parseCommon(type, token, depth))
4895
4901
  return;
4896
4902
 
4897
4903
  switch (token) {
@@ -4905,22 +4911,22 @@ function parse(source, root, options) {
4905
4911
  throw illegal(token);
4906
4912
  /* eslint-disable no-fallthrough */
4907
4913
  case "repeated":
4908
- parseField(type, token);
4914
+ parseField(type, token, undefined, depth + 1);
4909
4915
  break;
4910
4916
 
4911
4917
  case "optional":
4912
4918
  /* istanbul ignore if */
4913
4919
  if (edition === "proto3") {
4914
- parseField(type, "proto3_optional");
4920
+ parseField(type, "proto3_optional", undefined, depth + 1);
4915
4921
  } else if (edition !== "proto2") {
4916
4922
  throw illegal(token);
4917
4923
  } else {
4918
- parseField(type, "optional");
4924
+ parseField(type, "optional", undefined, depth + 1);
4919
4925
  }
4920
4926
  break;
4921
4927
 
4922
4928
  case "oneof":
4923
- parseOneOf(type, token);
4929
+ parseOneOf(type, token, depth + 1);
4924
4930
  break;
4925
4931
 
4926
4932
  case "extensions":
@@ -4938,7 +4944,7 @@ function parse(source, root, options) {
4938
4944
  }
4939
4945
 
4940
4946
  push(token);
4941
- parseField(type, "optional");
4947
+ parseField(type, "optional", undefined, depth + 1);
4942
4948
  break;
4943
4949
  }
4944
4950
  });
@@ -4948,10 +4954,10 @@ function parse(source, root, options) {
4948
4954
  }
4949
4955
  }
4950
4956
 
4951
- function parseField(parent, rule, extend) {
4957
+ function parseField(parent, rule, extend, depth) {
4952
4958
  var type = next();
4953
4959
  if (type === "group") {
4954
- parseGroup(parent, rule);
4960
+ parseGroup(parent, rule, depth);
4955
4961
  return;
4956
4962
  }
4957
4963
  // Type names can consume multiple tokens, in multiple variants:
@@ -5008,7 +5014,8 @@ function parse(source, root, options) {
5008
5014
  }
5009
5015
  }
5010
5016
 
5011
- function parseGroup(parent, rule) {
5017
+ function parseGroup(parent, rule, depth) {
5018
+ depth = util.checkDepth(depth);
5012
5019
  if (edition >= 2023) {
5013
5020
  throw illegal("group");
5014
5021
  }
@@ -5036,20 +5043,20 @@ function parse(source, root, options) {
5036
5043
  break;
5037
5044
  case "required":
5038
5045
  case "repeated":
5039
- parseField(type, token);
5046
+ parseField(type, token, undefined, depth + 1);
5040
5047
  break;
5041
5048
 
5042
5049
  case "optional":
5043
5050
  /* istanbul ignore if */
5044
5051
  if (edition === "proto3") {
5045
- parseField(type, "proto3_optional");
5052
+ parseField(type, "proto3_optional", undefined, depth + 1);
5046
5053
  } else {
5047
- parseField(type, "optional");
5054
+ parseField(type, "optional", undefined, depth + 1);
5048
5055
  }
5049
5056
  break;
5050
5057
 
5051
5058
  case "message":
5052
- parseType(type, token);
5059
+ parseType(type, token, depth + 1);
5053
5060
  break;
5054
5061
 
5055
5062
  case "enum":
@@ -5108,7 +5115,7 @@ function parse(source, root, options) {
5108
5115
  parent.add(field);
5109
5116
  }
5110
5117
 
5111
- function parseOneOf(parent, token) {
5118
+ function parseOneOf(parent, token, depth) {
5112
5119
 
5113
5120
  /* istanbul ignore if */
5114
5121
  if (!nameRe.test(token = next()))
@@ -5121,7 +5128,7 @@ function parse(source, root, options) {
5121
5128
  skip(";");
5122
5129
  } else {
5123
5130
  push(token);
5124
- parseField(oneof, "optional");
5131
+ parseField(oneof, "optional", undefined, depth);
5125
5132
  }
5126
5133
  });
5127
5134
  parent.add(oneof);
@@ -5226,7 +5233,8 @@ function parse(source, root, options) {
5226
5233
  setParsedOption(parent, option, optionValue, propName);
5227
5234
  }
5228
5235
 
5229
- function parseOptionValue(parent, name) {
5236
+ function parseOptionValue(parent, name, depth) {
5237
+ depth = util.checkDepth(depth);
5230
5238
  // { a: "foo" b { c: "bar" } }
5231
5239
  if (skip("{", true)) {
5232
5240
  var objectResult = {};
@@ -5249,7 +5257,7 @@ function parse(source, root, options) {
5249
5257
  // option (my_option) = {
5250
5258
  // repeated_value: [ "foo", "bar" ]
5251
5259
  // };
5252
- value = parseOptionValue(parent, name + "." + token);
5260
+ value = parseOptionValue(parent, name + "." + token, depth + 1);
5253
5261
  } else if (peek() === "[") {
5254
5262
  value = [];
5255
5263
  var lastValue;
@@ -5314,7 +5322,8 @@ function parse(source, root, options) {
5314
5322
  return parent;
5315
5323
  }
5316
5324
 
5317
- function parseService(parent, token) {
5325
+ function parseService(parent, token, depth) {
5326
+ depth = util.checkDepth(depth);
5318
5327
 
5319
5328
  /* istanbul ignore if */
5320
5329
  if (!nameRe.test(token = next()))
@@ -5322,7 +5331,7 @@ function parse(source, root, options) {
5322
5331
 
5323
5332
  var service = new Service(token);
5324
5333
  ifBlock(service, function parseService_block(token) {
5325
- if (parseCommon(service, token)) {
5334
+ if (parseCommon(service, token, depth)) {
5326
5335
  return;
5327
5336
  }
5328
5337
 
@@ -5388,7 +5397,7 @@ function parse(source, root, options) {
5388
5397
  parent.add(method);
5389
5398
  }
5390
5399
 
5391
- function parseExtension(parent, token) {
5400
+ function parseExtension(parent, token, depth) {
5392
5401
 
5393
5402
  /* istanbul ignore if */
5394
5403
  if (!typeRefRe.test(token = next()))
@@ -5400,15 +5409,15 @@ function parse(source, root, options) {
5400
5409
 
5401
5410
  case "required":
5402
5411
  case "repeated":
5403
- parseField(parent, token, reference);
5412
+ parseField(parent, token, reference, depth + 1);
5404
5413
  break;
5405
5414
 
5406
5415
  case "optional":
5407
5416
  /* istanbul ignore if */
5408
5417
  if (edition === "proto3") {
5409
- parseField(parent, "proto3_optional", reference);
5418
+ parseField(parent, "proto3_optional", reference, depth + 1);
5410
5419
  } else {
5411
- parseField(parent, "optional", reference);
5420
+ parseField(parent, "optional", reference, depth + 1);
5412
5421
  }
5413
5422
  break;
5414
5423
 
@@ -5417,7 +5426,7 @@ function parse(source, root, options) {
5417
5426
  if (edition === "proto2" || !typeRefRe.test(token))
5418
5427
  throw illegal(token);
5419
5428
  push(token);
5420
- parseField(parent, "optional", reference);
5429
+ parseField(parent, "optional", reference, depth + 1);
5421
5430
  break;
5422
5431
  }
5423
5432
  });
@@ -5469,7 +5478,7 @@ function parse(source, root, options) {
5469
5478
  default:
5470
5479
 
5471
5480
  /* istanbul ignore else */
5472
- if (parseCommon(ptr, token)) {
5481
+ if (parseCommon(ptr, token, 0)) {
5473
5482
  head = false;
5474
5483
  continue;
5475
5484
  }
@@ -6041,14 +6050,16 @@ function Root(options) {
6041
6050
  * Loads a namespace descriptor into a root namespace.
6042
6051
  * @param {INamespace} json Namespace descriptor
6043
6052
  * @param {Root} [root] Root namespace, defaults to create a new one if omitted
6053
+ * @param {number} [depth] Current nesting depth, defaults to `0`
6044
6054
  * @returns {Root} Root namespace
6045
6055
  */
6046
- Root.fromJSON = function fromJSON(json, root) {
6056
+ Root.fromJSON = function fromJSON(json, root, depth) {
6057
+ depth = util.checkDepth(depth);
6047
6058
  if (!root)
6048
6059
  root = new Root();
6049
6060
  if (json.options)
6050
6061
  root.setOptions(json.options);
6051
- return root.addJSON(json.nested).resolveAll();
6062
+ return root.addJSON(json.nested, depth).resolveAll();
6052
6063
  };
6053
6064
 
6054
6065
  /**
@@ -6642,17 +6653,19 @@ function Service(name, options) {
6642
6653
  * Constructs a service from a service descriptor.
6643
6654
  * @param {string} name Service name
6644
6655
  * @param {IService} json Service descriptor
6656
+ * @param {number} [depth] Current nesting depth, defaults to `0`
6645
6657
  * @returns {Service} Created service
6646
6658
  * @throws {TypeError} If arguments are invalid
6647
6659
  */
6648
- Service.fromJSON = function fromJSON(name, json) {
6660
+ Service.fromJSON = function fromJSON(name, json, depth) {
6661
+ depth = util.checkDepth(depth);
6649
6662
  var service = new Service(name, json.options);
6650
6663
  /* istanbul ignore else */
6651
6664
  if (json.methods)
6652
6665
  for (var names = Object.keys(json.methods), i = 0; i < names.length; ++i)
6653
6666
  service.add(Method.fromJSON(names[i], json.methods[names[i]]));
6654
6667
  if (json.nested)
6655
- service.addJSON(json.nested);
6668
+ service.addJSON(json.nested, depth);
6656
6669
  if (json.edition)
6657
6670
  service._edition = json.edition;
6658
6671
  service.comment = json.comment;
@@ -7440,9 +7453,11 @@ function clearCache(type) {
7440
7453
  * Creates a message type from a message type descriptor.
7441
7454
  * @param {string} name Message name
7442
7455
  * @param {IType} json Message type descriptor
7456
+ * @param {number} [depth] Current nesting depth, defaults to `0`
7443
7457
  * @returns {Type} Created message type
7444
7458
  */
7445
- Type.fromJSON = function fromJSON(name, json) {
7459
+ Type.fromJSON = function fromJSON(name, json, depth) {
7460
+ depth = util.checkDepth(depth);
7446
7461
  var type = new Type(name, json.options);
7447
7462
  type.extensions = json.extensions;
7448
7463
  type.reserved = json.reserved;
@@ -7469,7 +7484,7 @@ Type.fromJSON = function fromJSON(name, json) {
7469
7484
  ? Enum.fromJSON
7470
7485
  : nested.methods !== undefined
7471
7486
  ? Service.fromJSON
7472
- : Namespace.fromJSON )(names[i], nested)
7487
+ : Namespace.fromJSON )(names[i], nested, depth + 1)
7473
7488
  );
7474
7489
  }
7475
7490
  if (json.extensions && json.extensions.length)
@@ -8057,6 +8072,20 @@ var reservedRe = util.patterns.reservedRe,
8057
8072
  */
8058
8073
  util.fs = util.inquire("fs");
8059
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
+
8060
8089
  /**
8061
8090
  * Converts an object's values to an array.
8062
8091
  * @param {Object.<string,*>} object Object to convert