protobufjs 8.7.1 → 8.8.0

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/dist/protobuf.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v8.7.1 (c) 2016, daniel wirtz
3
- * compiled mon, 13 jul 2026 11:04:12 utc
2
+ * protobuf.js v8.8.0 (c) 2016, daniel wirtz
3
+ * compiled thu, 27 aug 2026 00:01:05 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -752,7 +752,11 @@ converter.toObject = function toObject(mtype) {
752
752
  ("d%s=%j", prop, arrayDefault)
753
753
  ("if(o.bytes!==Array)d%s=util.newBuffer(d%s)", prop, prop)
754
754
  ("}");
755
- } else gen
755
+ } else if ((field.type === "double" || field.type === "float") && typeof field.typeDefault === "number"
756
+ && (!isFinite(field.typeDefault) || Object.is(field.typeDefault, -0))) gen
757
+ ("d%s=%f", prop, field.typeDefault)
758
+ ("if(o.json&&!isFinite(d%s))d%s=String(d%s)", prop, prop, prop);
759
+ else gen
756
760
  ("d%s=%j", prop, field.typeDefault); // also messages (=null)
757
761
  } gen
758
762
  ("}");
@@ -849,7 +853,17 @@ function decoder(mtype) {
849
853
  ("if(q===undefined)q=0")
850
854
  ("if(q>Reader.recursionLimit)")
851
855
  ("throw Error(\"max depth exceeded\")")
852
- ("var c=l===undefined?r.len:r.pos+l,m=g||new C" + (hasMapField ? ",k,v" : needsValueVar ? ",v" : ""))
856
+ ("var c,m" + (hasMapField ? ",k,v" : needsValueVar ? ",v" : ""))
857
+ ("if(l===undefined)")
858
+ ("c=r.len")
859
+ ("else{")
860
+ ("c=r.pos+l")
861
+ ("if(c>r.len)")
862
+ ("throw RangeError(\"index out of range\")")
863
+ ("l=r.len")
864
+ ("r.len=c")
865
+ ("}")
866
+ ("m=g||new C")
853
867
  ("while(r.pos<c){")
854
868
  ("var s=r.pos")
855
869
  ("var t=r.tag()")
@@ -876,7 +890,10 @@ function decoder(mtype) {
876
890
  ("if(%s===util.emptyObject)", ref)
877
891
  ("%s={}", ref);
878
892
  gen
879
- ("var c2=r.uint32()+r.pos");
893
+ ("var c2=r.uint32()+r.pos")
894
+ ("if(c2>r.len)")
895
+ ("throw RangeError(\"index out of range\")")
896
+ ("r.len=c2");
880
897
 
881
898
  if (types.defaults[field.keyType] !== undefined) gen
882
899
  ("k=%j", types.defaults[field.keyType]);
@@ -914,6 +931,10 @@ function decoder(mtype) {
914
931
  ("}")
915
932
  ("r.skipType(u,q,t2)")
916
933
  ("}");
934
+ gen
935
+ ("if(r.pos!==c2)")
936
+ ("throw RangeError(\"index out of range\")")
937
+ ("r.len=c");
917
938
 
918
939
  if (closed) { gen
919
940
  ("if(types[%i].valuesById[v]===undefined){", i);
@@ -947,6 +968,9 @@ function decoder(mtype) {
947
968
  if (closed) {
948
969
  gen
949
970
  ("var c2=r.uint32()+r.pos")
971
+ ("if(c2>r.len)")
972
+ ("throw RangeError(\"index out of range\")")
973
+ ("r.len=c2")
950
974
  ("while(r.pos<c2){")
951
975
  ("s=r.pos")
952
976
  ("v=r.%s()", type)
@@ -957,6 +981,10 @@ function decoder(mtype) {
957
981
  ("}else");
958
982
  genPreserveUnknown(gen, "util.rawField(" + field.id + ",0,r.raw(s,r.pos))")
959
983
  ("}");
984
+ gen
985
+ ("if(r.pos!==c2)")
986
+ ("throw RangeError(\"index out of range\")")
987
+ ("r.len=c");
960
988
  } else gen
961
989
  ("if(!(%s&&%s.length))", ref, ref)
962
990
  ("%s=[]", ref)
@@ -1065,6 +1093,11 @@ function decoder(mtype) {
1065
1093
  ("r.skipType(%s,q,t)", i ? "u" : "t&7");
1066
1094
  genPreserveUnknown(gen, "r.raw(s,r.pos)")
1067
1095
  ("}")
1096
+ ("if(l!==undefined){")
1097
+ ("if(r.pos!==c)")
1098
+ ("throw RangeError(\"index out of range\")")
1099
+ ("r.len=l")
1100
+ ("}")
1068
1101
  ("if(z!==undefined)")
1069
1102
  ("throw Error(\"missing end group\")");
1070
1103
 
@@ -1285,14 +1318,23 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
1285
1318
  */
1286
1319
  this.reserved = undefined; // toJSON
1287
1320
 
1321
+ /**
1322
+ * Declared symbol visibility, if any.
1323
+ * @type {"local"|"export"|undefined}
1324
+ */
1325
+ this.visibility = undefined; // toJSON
1326
+
1288
1327
  // Note that values inherit valuesById on their prototype which makes them a TypeScript-
1289
1328
  // compatible enum. This is used by pbts to write actual enum definitions that work for
1290
1329
  // static and reflection code alike instead of emitting generic object definitions.
1291
1330
 
1292
1331
  if (values)
1293
1332
  for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)
1294
- if (keys[i] !== "__proto__" && typeof values[keys[i]] === "number") // use forward entries only
1295
- this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
1333
+ if (keys[i] !== "__proto__" && typeof values[keys[i]] === "number") { // use forward entries only
1334
+ this.values[keys[i]] = values[keys[i]];
1335
+ if (this.valuesById[values[keys[i]]] === undefined)
1336
+ this.valuesById[values[keys[i]]] = keys[i];
1337
+ }
1296
1338
  }
1297
1339
 
1298
1340
  /**
@@ -1318,6 +1360,7 @@ Enum.prototype._resolveFeatures = function _resolveFeatures(edition) {
1318
1360
  * @property {Object.<string,*>} [options] Enum options
1319
1361
  * @property {Object.<string,Object.<string,*>>} [valuesOptions] Enum value options
1320
1362
  * @property {Array.<number[]|string>} [reserved] Reserved ranges
1363
+ * @property {"local"|"export"} [visibility] Declared symbol visibility
1321
1364
  * @property {string|null} [comment] Enum comment
1322
1365
  * @property {Object.<string,string|null>} [comments] Value comments
1323
1366
  */
@@ -1332,6 +1375,8 @@ Enum.prototype._resolveFeatures = function _resolveFeatures(edition) {
1332
1375
  Enum.fromJSON = function fromJSON(name, json) {
1333
1376
  var enm = new Enum(name, json.values, json.options, json.comment, json.comments, json.valuesOptions);
1334
1377
  enm.reserved = json.reserved;
1378
+ if (json.visibility)
1379
+ enm.visibility = json.visibility;
1335
1380
  if (json.edition)
1336
1381
  enm._edition = json.edition;
1337
1382
  enm._defaultEdition = "proto3"; // For backwards-compatibility.
@@ -1351,6 +1396,7 @@ Enum.prototype.toJSON = function toJSON(toJSONOptions) {
1351
1396
  "valuesOptions" , this.valuesOptions,
1352
1397
  "values" , this.values,
1353
1398
  "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
1399
+ "visibility" , this.visibility,
1354
1400
  "comment" , keepComments ? this.comment : undefined,
1355
1401
  "comments" , keepComments ? this.comments : undefined
1356
1402
  ]);
@@ -1821,12 +1867,17 @@ Field.prototype.resolve = function resolve() {
1821
1867
 
1822
1868
  // convert to internal data type if necesssary
1823
1869
  if (this.long) {
1824
- this.typeDefault = util.Long.fromNumber(this.typeDefault, this.type === "uint64" || this.type === "fixed64");
1870
+ var unsigned = this.type === "uint64" || this.type === "fixed64";
1871
+ this.typeDefault = typeof this.typeDefault === "string"
1872
+ ? util.Long.fromString(this.typeDefault, unsigned)
1873
+ : util.Long.fromNumber(this.typeDefault, unsigned);
1825
1874
 
1826
1875
  /* istanbul ignore else */
1827
1876
  if (Object.freeze)
1828
1877
  Object.freeze(this.typeDefault); // long instances are meant to be immutable anyway (i.e. use small int cache that even requires it)
1829
1878
 
1879
+ } else if (types.long[this.type] !== undefined && typeof this.typeDefault === "string") {
1880
+ this.typeDefault = parseInt(this.typeDefault, 10);
1830
1881
  } else if (this.bytes && typeof this.typeDefault === "string") {
1831
1882
  var buf;
1832
1883
  if (util.base64.test(this.typeDefault))
@@ -3170,10 +3221,11 @@ var Root; // cyclic
3170
3221
 
3171
3222
  /* eslint-disable no-warning-comments */
3172
3223
  // TODO: Replace with embedded proto.
3173
- var editions2024Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE2024", default_symbol_visibility: "EXPORT_TOP_LEVEL" };
3174
- var editions2023Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
3175
3224
  var proto2Defaults = {enum_type: "CLOSED", field_presence: "EXPLICIT", json_format: "LEGACY_BEST_EFFORT", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "EXPANDED", utf8_validation: "NONE", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
3176
3225
  var proto3Defaults = {enum_type: "OPEN", field_presence: "IMPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
3226
+ var editions2023Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
3227
+ var editions2024Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE2024", default_symbol_visibility: "EXPORT_TOP_LEVEL" };
3228
+ var editions2026Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE2026", default_symbol_visibility: "STRICT", enforce_proto_limits: "PROTO_LIMITS2026" };
3177
3229
 
3178
3230
  /**
3179
3231
  * Constructs a new reflection object instance.
@@ -3387,6 +3439,8 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
3387
3439
  defaults = Object.assign({}, editions2023Defaults);
3388
3440
  } else if (edition === "2024") {
3389
3441
  defaults = Object.assign({}, editions2024Defaults);
3442
+ } else if (edition === "2026") {
3443
+ defaults = Object.assign({}, editions2026Defaults);
3390
3444
  } else {
3391
3445
  throw new Error("Unknown edition: " + edition);
3392
3446
  }
@@ -3812,6 +3866,8 @@ var base10Re = /^[1-9][0-9]*$/,
3812
3866
  base16NegRe = /^-?0[x][0-9a-fA-F]+$/,
3813
3867
  base8Re = /^0[0-7]+$/,
3814
3868
  base8NegRe = /^-?0[0-7]+$/,
3869
+ integerTypeRe = /^(?:u?int|sint|s?fixed)(?:32|64)$/,
3870
+ unsignedTypeRe = /^(?:uint|fixed)(?:32|64)$/,
3815
3871
  numberRe = util.patterns.numberRe,
3816
3872
  nameRe = /^[a-zA-Z_][a-zA-Z_0-9]*$/,
3817
3873
  typeRefRe = util.patterns.typeRefRe;
@@ -3991,7 +4047,7 @@ function parse(source, root, options) {
3991
4047
  case "nan": case "NAN": case "Nan": case "NaN":
3992
4048
  return NaN;
3993
4049
  case "0":
3994
- return 0;
4050
+ return sign * 0;
3995
4051
  }
3996
4052
  if (base10Re.test(token))
3997
4053
  return sign * parseInt(token, 10);
@@ -4008,32 +4064,31 @@ function parse(source, root, options) {
4008
4064
  throw illegal(token, "number", insideTryCatch);
4009
4065
  }
4010
4066
 
4011
- function parseId(token, acceptNegative, max) {
4012
- if (token === null) {
4067
+ function parseInteger(token, acceptNegative, name) {
4068
+ if (token === null)
4013
4069
  throw illegal(token, "end of input");
4014
- }
4070
+ if (!acceptNegative && token.charAt(0) === "-")
4071
+ throw illegal(token, name || "integer");
4072
+ if (token === "0" || token === "-0")
4073
+ return 0;
4074
+ var value;
4075
+ if (base10NegRe.test(token))
4076
+ value = parseInt(token, 10);
4077
+ else if (base16NegRe.test(token))
4078
+ value = parseInt(token, 16);
4079
+ else if (base8NegRe.test(token))
4080
+ value = parseInt(token, 8);
4081
+ else
4082
+ throw illegal(token, name || "integer");
4083
+ return value || 0;
4084
+ }
4085
+
4086
+ function parseId(token, acceptNegative, max) {
4015
4087
  switch (token) {
4016
4088
  case "max": case "MAX": case "Max":
4017
4089
  return max || maxFieldId;
4018
- case "0":
4019
- return 0;
4020
4090
  }
4021
-
4022
- /* istanbul ignore if */
4023
- if (!acceptNegative && token.charAt(0) === "-")
4024
- throw illegal(token, "id");
4025
-
4026
- if (base10NegRe.test(token))
4027
- return parseInt(token, 10);
4028
- if (base16NegRe.test(token))
4029
- return parseInt(token, 16);
4030
-
4031
- /* istanbul ignore else */
4032
- if (base8NegRe.test(token))
4033
- return parseInt(token, 8);
4034
-
4035
- /* istanbul ignore next */
4036
- throw illegal(token, "id");
4091
+ return parseInteger(token, acceptNegative, "id");
4037
4092
  }
4038
4093
 
4039
4094
  function parsePackage() {
@@ -4096,7 +4151,7 @@ function parse(source, root, options) {
4096
4151
  function parseEdition() {
4097
4152
  skip("=");
4098
4153
  edition = readString();
4099
- const supportedEditions = ["2023", "2024"];
4154
+ const supportedEditions = ["2023", "2024", "2026"];
4100
4155
 
4101
4156
  /* istanbul ignore if */
4102
4157
  if (!supportedEditions.includes(edition))
@@ -4130,6 +4185,7 @@ function parse(source, root, options) {
4130
4185
  if (edition < "2024") {
4131
4186
  return false;
4132
4187
  }
4188
+ var visibility = token;
4133
4189
  token = next();
4134
4190
  if (token === "export" || token === "local") {
4135
4191
  return false;
@@ -4137,9 +4193,11 @@ function parse(source, root, options) {
4137
4193
  if (token !== "message" && token !== "enum") {
4138
4194
  return false;
4139
4195
  }
4140
- /* eslint-disable no-warning-comments */
4141
- // TODO: actually enforce visiblity modifiers like protoc does.
4142
- return parseCommon(parent, token, depth);
4196
+ (token === "message"
4197
+ ? parseType(parent, token, depth + 1)
4198
+ : parseEnum(parent, token)
4199
+ ).visibility = visibility;
4200
+ return true;
4143
4201
 
4144
4202
  case "service":
4145
4203
  parseService(parent, token, depth + 1);
@@ -4244,6 +4302,7 @@ function parse(source, root, options) {
4244
4302
  if (parent === ptr) {
4245
4303
  topLevelObjects.push(type);
4246
4304
  }
4305
+ return type;
4247
4306
  }
4248
4307
 
4249
4308
  function parseField(parent, rule, extend, depth) {
@@ -4508,6 +4567,7 @@ function parse(source, root, options) {
4508
4567
  if (parent === ptr) {
4509
4568
  topLevelObjects.push(enm);
4510
4569
  }
4570
+ return enm;
4511
4571
  }
4512
4572
 
4513
4573
  function parseEnumValue(token) {
@@ -4670,7 +4730,9 @@ function parse(source, root, options) {
4670
4730
  return objectResult;
4671
4731
  }
4672
4732
 
4673
- var simpleValue = readValue(true);
4733
+ var simpleValue = name === "default" && parent instanceof Field && integerTypeRe.test(parent.type)
4734
+ ? parseInteger(next(), !unsignedTypeRe.test(parent.type))
4735
+ : readValue(true);
4674
4736
  setOption(parent, name, simpleValue);
4675
4737
  return simpleValue;
4676
4738
  // Does not enforce a delimiter to be universal
@@ -4996,12 +5058,32 @@ Reader.prototype.raw = function read_raw(start, end) {
4996
5058
  return this.buf.subarray(start, end);
4997
5059
  };
4998
5060
 
5061
+ function readVarint32NearEnd(reader) {
5062
+ // Safely read up to four bytes of a varint32 near the reader limit
5063
+ var value = 0;
5064
+ for (var i = 0; i < 4; ++i) {
5065
+ if (reader.pos >= reader.len)
5066
+ throw indexOutOfRange(reader);
5067
+ var b = reader.buf[reader.pos++];
5068
+ value = (value | (b & 127) << i * 7) >>> 0;
5069
+ if (b < 128)
5070
+ return value;
5071
+ }
5072
+ throw indexOutOfRange(reader);
5073
+ }
5074
+
4999
5075
  /**
5000
5076
  * Reads a varint as an unsigned 32 bit value.
5001
5077
  * @function
5002
5078
  * @returns {number} Value read
5003
5079
  */
5004
5080
  Reader.prototype.uint32 = function read_uint32() {
5081
+ if (this.len - this.pos < 5) {
5082
+ if (this.pos >= this.len)
5083
+ throw indexOutOfRange(this);
5084
+ if (this.buf[this.pos] >= 128)
5085
+ return readVarint32NearEnd(this);
5086
+ }
5005
5087
  var buf = this.buf,
5006
5088
  pos = this.pos,
5007
5089
  value = (buf[pos] & 127) >>> 0;
@@ -5052,6 +5134,12 @@ Reader.prototype.uint32 = function read_uint32() {
5052
5134
  * @returns {number} Tag read
5053
5135
  */
5054
5136
  Reader.prototype.tag = function read_tag() {
5137
+ if (this.len - this.pos < 5) {
5138
+ if (this.pos >= this.len)
5139
+ throw indexOutOfRange(this);
5140
+ if (this.buf[this.pos] >= 128)
5141
+ return readVarint32NearEnd(this);
5142
+ }
5055
5143
  var buf = this.buf,
5056
5144
  pos = this.pos,
5057
5145
  value = (buf[pos] & 127) >>> 0;
@@ -5297,9 +5385,22 @@ Reader.prototype.double = function read_double() {
5297
5385
  */
5298
5386
  Reader.prototype.uint32s = function read_uint32s(array) {
5299
5387
  if (array === undefined) array = [];
5300
- var end = this.uint32() + this.pos;
5301
- while (this.pos < end)
5302
- array.push(this.uint32());
5388
+ var end = this.uint32() + this.pos, len = this.len, buf = this.buf, pos = this.pos, value;
5389
+ if (end > len) throw indexOutOfRange(this, end - this.pos);
5390
+ this.len = end;
5391
+ while (pos < end) {
5392
+ value = buf[pos++];
5393
+ if (value < 128)
5394
+ array.push(value);
5395
+ else {
5396
+ this.pos = pos - 1;
5397
+ array.push(this.uint32());
5398
+ pos = this.pos;
5399
+ }
5400
+ }
5401
+ this.pos = pos;
5402
+ if (pos !== end) throw RangeError("index out of range");
5403
+ this.len = len;
5303
5404
  return array;
5304
5405
  };
5305
5406
 
@@ -5310,9 +5411,22 @@ Reader.prototype.uint32s = function read_uint32s(array) {
5310
5411
  */
5311
5412
  Reader.prototype.int32s = function read_int32s(array) {
5312
5413
  if (array === undefined) array = [];
5313
- var end = this.uint32() + this.pos;
5314
- while (this.pos < end)
5315
- array.push(this.int32());
5414
+ var end = this.uint32() + this.pos, len = this.len, buf = this.buf, pos = this.pos, value;
5415
+ if (end > len) throw indexOutOfRange(this, end - this.pos);
5416
+ this.len = end;
5417
+ while (pos < end) {
5418
+ value = buf[pos++];
5419
+ if (value < 128)
5420
+ array.push(value);
5421
+ else {
5422
+ this.pos = pos - 1;
5423
+ array.push(this.int32());
5424
+ pos = this.pos;
5425
+ }
5426
+ }
5427
+ this.pos = pos;
5428
+ if (pos !== end) throw RangeError("index out of range");
5429
+ this.len = len;
5316
5430
  return array;
5317
5431
  };
5318
5432
 
@@ -5323,9 +5437,13 @@ Reader.prototype.int32s = function read_int32s(array) {
5323
5437
  */
5324
5438
  Reader.prototype.sint32s = function read_sint32s(array) {
5325
5439
  if (array === undefined) array = [];
5326
- var end = this.uint32() + this.pos;
5440
+ var end = this.uint32() + this.pos, len = this.len;
5441
+ if (end > len) throw indexOutOfRange(this, end - this.pos);
5442
+ this.len = end;
5327
5443
  while (this.pos < end)
5328
5444
  array.push(this.sint32());
5445
+ if (this.pos !== end) throw RangeError("index out of range");
5446
+ this.len = len;
5329
5447
  return array;
5330
5448
  };
5331
5449
 
@@ -5336,9 +5454,22 @@ Reader.prototype.sint32s = function read_sint32s(array) {
5336
5454
  */
5337
5455
  Reader.prototype.bools = function read_bools(array) {
5338
5456
  if (array === undefined) array = [];
5339
- var end = this.uint32() + this.pos;
5340
- while (this.pos < end)
5341
- array.push(this.bool());
5457
+ var end = this.uint32() + this.pos, len = this.len, buf = this.buf, pos = this.pos, value;
5458
+ if (end > len) throw indexOutOfRange(this, end - this.pos);
5459
+ this.len = end;
5460
+ while (pos < end) {
5461
+ value = buf[pos++];
5462
+ if (value < 128)
5463
+ array.push(value !== 0);
5464
+ else {
5465
+ this.pos = pos - 1;
5466
+ array.push(this.bool());
5467
+ pos = this.pos;
5468
+ }
5469
+ }
5470
+ this.pos = pos;
5471
+ if (pos !== end) throw RangeError("index out of range");
5472
+ this.len = len;
5342
5473
  return array;
5343
5474
  };
5344
5475
 
@@ -5457,9 +5588,13 @@ Reader.prototype.doubles = function read_doubles(array) {
5457
5588
  */
5458
5589
  Reader.prototype.uint64s = function read_uint64s(array) {
5459
5590
  if (array === undefined) array = [];
5460
- var end = this.uint32() + this.pos;
5591
+ var end = this.uint32() + this.pos, len = this.len;
5592
+ if (end > len) throw indexOutOfRange(this, end - this.pos);
5593
+ this.len = end;
5461
5594
  while (this.pos < end)
5462
5595
  array.push(this.uint64());
5596
+ if (this.pos !== end) throw RangeError("index out of range");
5597
+ this.len = len;
5463
5598
  return array;
5464
5599
  };
5465
5600
 
@@ -5470,9 +5605,13 @@ Reader.prototype.uint64s = function read_uint64s(array) {
5470
5605
  */
5471
5606
  Reader.prototype.int64s = function read_int64s(array) {
5472
5607
  if (array === undefined) array = [];
5473
- var end = this.uint32() + this.pos;
5608
+ var end = this.uint32() + this.pos, len = this.len;
5609
+ if (end > len) throw indexOutOfRange(this, end - this.pos);
5610
+ this.len = end;
5474
5611
  while (this.pos < end)
5475
5612
  array.push(this.int64());
5613
+ if (this.pos !== end) throw RangeError("index out of range");
5614
+ this.len = len;
5476
5615
  return array;
5477
5616
  };
5478
5617
 
@@ -5483,9 +5622,13 @@ Reader.prototype.int64s = function read_int64s(array) {
5483
5622
  */
5484
5623
  Reader.prototype.sint64s = function read_sint64s(array) {
5485
5624
  if (array === undefined) array = [];
5486
- var end = this.uint32() + this.pos;
5625
+ var end = this.uint32() + this.pos, len = this.len;
5626
+ if (end > len) throw indexOutOfRange(this, end - this.pos);
5627
+ this.len = end;
5487
5628
  while (this.pos < end)
5488
5629
  array.push(this.sint64());
5630
+ if (this.pos !== end) throw RangeError("index out of range");
5631
+ this.len = len;
5489
5632
  return array;
5490
5633
  };
5491
5634
 
@@ -7113,6 +7256,12 @@ function Type(name, options) {
7113
7256
  */
7114
7257
  this.group = undefined; // toJSON
7115
7258
 
7259
+ /**
7260
+ * Declared symbol visibility, if any.
7261
+ * @type {"local"|"export"|undefined}
7262
+ */
7263
+ this.visibility = undefined; // toJSON
7264
+
7116
7265
  /**
7117
7266
  * Cached fields by id.
7118
7267
  * @type {Object.<number,Field>|null}
@@ -7297,6 +7446,7 @@ function clearCache(type) {
7297
7446
  * @property {number[][]} [extensions] Extension ranges
7298
7447
  * @property {Array.<number[]|string>} [reserved] Reserved ranges
7299
7448
  * @property {boolean} [group=false] Whether a legacy group or not
7449
+ * @property {"local"|"export"} [visibility] Declared symbol visibility
7300
7450
  * @property {string|null} [comment] Message type comment
7301
7451
  */
7302
7452
 
@@ -7347,6 +7497,8 @@ Type.fromJSON = function fromJSON(name, json, depth) {
7347
7497
  type.reserved = json.reserved;
7348
7498
  if (json.group)
7349
7499
  type.group = true;
7500
+ if (json.visibility)
7501
+ type.visibility = json.visibility;
7350
7502
  if (json.comment)
7351
7503
  type.comment = json.comment;
7352
7504
  if (json.edition)
@@ -7371,6 +7523,7 @@ Type.prototype.toJSON = function toJSON(toJSONOptions) {
7371
7523
  "extensions" , this.extensions && this.extensions.length ? this.extensions : undefined,
7372
7524
  "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
7373
7525
  "group" , this.group || undefined,
7526
+ "visibility" , this.visibility,
7374
7527
  "nested" , inherited && inherited.nested || undefined,
7375
7528
  "comment" , keepComments ? this.comment : undefined
7376
7529
  ]);
@@ -8451,7 +8604,9 @@ function codegen(functionParams, functionName) {
8451
8604
  formatStringOrScope = formatStringOrScope.replace(/%([%dfijs])/g, function replace($0, $1) {
8452
8605
  var value = formatParams[formatOffset++];
8453
8606
  switch ($1) {
8454
- case "d": case "f": return String(Number(value));
8607
+ case "d": case "f":
8608
+ value = Number(value);
8609
+ return Object.is(value, -0) ? "-0" : String(value);
8455
8610
  case "i": return String(Math.floor(value));
8456
8611
  case "j": return JSON.stringify(value);
8457
8612
  case "s": return String(value);
@@ -9945,7 +10100,6 @@ function pool(alloc, slice, size) {
9945
10100
  * @namespace
9946
10101
  */
9947
10102
  var utf8 = exports,
9948
- replacementChar = "\ufffd",
9949
10103
  looseDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
9950
10104
  strictDecoder;
9951
10105
  var TEXT_DECODER_MIN_LENGTH = 64;
@@ -9980,31 +10134,6 @@ utf8.length = function utf8_length(string) {
9980
10134
  return len;
9981
10135
  };
9982
10136
 
9983
- function utf8_read_js(buffer, start, end, str) {
9984
- for (var i = start; i < end;) {
9985
- var t = buffer[i++];
9986
- if (t <= 0x7F) {
9987
- str += String.fromCharCode(t);
9988
- } else if (t >= 0xC0 && t < 0xE0) {
9989
- var c2 = (t & 0x1F) << 6 | buffer[i++] & 0x3F;
9990
- str += c2 >= 0x80 ? String.fromCharCode(c2) : replacementChar;
9991
- } else if (t >= 0xE0 && t < 0xF0) {
9992
- var c3 = (t & 0xF) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
9993
- str += c3 >= 0x800 ? String.fromCharCode(c3) : replacementChar;
9994
- } else if (t >= 0xF0) {
9995
- var t2 = (t & 7) << 18 | (buffer[i++] & 0x3F) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
9996
- if (t2 < 0x10000 || t2 > 0x10FFFF)
9997
- str += replacementChar;
9998
- else {
9999
- t2 -= 0x10000;
10000
- str += String.fromCharCode(0xD800 + (t2 >> 10));
10001
- str += String.fromCharCode(0xDC00 + (t2 & 0x3FF));
10002
- }
10003
- }
10004
- }
10005
- return str;
10006
- }
10007
-
10008
10137
  function utf8_read_decoder(decoder, buffer, start, end) {
10009
10138
  var source = start === 0 && end === buffer.length
10010
10139
  ? buffer
@@ -10039,14 +10168,14 @@ utf8.read = function utf8_read_loose(buffer, start, end) {
10039
10168
  c7 = buffer[i + 6];
10040
10169
  c8 = buffer[i + 7];
10041
10170
  if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
10042
- return utf8_read_js(buffer, i, end, str);
10171
+ return str + utf8_read_decoder(looseDecoder, buffer, i, end);
10043
10172
  str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
10044
10173
  }
10045
10174
 
10046
10175
  for (; i < end; ++i) {
10047
10176
  c1 = buffer[i];
10048
10177
  if (c1 & 0x80)
10049
- return utf8_read_js(buffer, i, end, str);
10178
+ return str + utf8_read_decoder(looseDecoder, buffer, i, end);
10050
10179
  str += String.fromCharCode(c1);
10051
10180
  }
10052
10181
 
@@ -10358,6 +10487,10 @@ var Message = require(12),
10358
10487
  wrappers[".google.protobuf.Any"] = {
10359
10488
 
10360
10489
  fromObject: function(object, depth) {
10490
+ if (depth === undefined)
10491
+ depth = 0;
10492
+ if (depth > util.recursionLimit)
10493
+ throw Error("max depth exceeded");
10361
10494
 
10362
10495
  // unwrap value type if mapped
10363
10496
  if (object && object["@type"]) {
@@ -10375,7 +10508,7 @@ wrappers[".google.protobuf.Any"] = {
10375
10508
  }
10376
10509
  return this.create({
10377
10510
  type_url: type_url,
10378
- value: type.encode(type.fromObject(object, depth === undefined ? 1 : depth + 1)).finish()
10511
+ value: type.encode(type.fromObject(object, depth + 1)).finish()
10379
10512
  });
10380
10513
  }
10381
10514
  }
@@ -10452,7 +10585,7 @@ function Writer() {
10452
10585
  * Backing buffer.
10453
10586
  * @type {Uint8Array}
10454
10587
  */
10455
- this.buf = this.constructor.alloc(64);
10588
+ this.buf = this.constructor.alloc(Writer.initialBufferSize);
10456
10589
 
10457
10590
  /**
10458
10591
  * Cached DataView over {@link Writer#buf}.
@@ -10467,6 +10600,12 @@ function Writer() {
10467
10600
  this.states = null;
10468
10601
  }
10469
10602
 
10603
+ /**
10604
+ * Initial backing buffer size in bytes. Defaults to 128.
10605
+ * @type {number}
10606
+ */
10607
+ Writer.initialBufferSize = 128;
10608
+
10470
10609
  /**
10471
10610
  * Current write position.
10472
10611
  * @name Writer#len