protobufjs 7.6.4 → 7.6.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "protobufjs",
3
- "version": "7.6.4",
3
+ "version": "7.6.6",
4
4
  "versionScheme": "~",
5
5
  "description": "Protocol Buffers for JavaScript (& TypeScript).",
6
6
  "author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
package/src/decoder.js CHANGED
@@ -22,7 +22,17 @@ function decoder(mtype) {
22
22
  ("if(n===undefined)n=0")
23
23
  ("if(n>Reader.recursionLimit)")
24
24
  ("throw Error(\"maximum nesting depth exceeded\")")
25
- ("var c=l===undefined?r.len:r.pos+l,m=new this.ctor" + (mtype.fieldsArray.filter(function(field) { return field.map; }).length ? ",k,value" : ""))
25
+ ("var c,m" + (mtype.fieldsArray.filter(function(field) { return field.map; }).length ? ",k,value" : ""))
26
+ ("if(l===undefined)")
27
+ ("c=r.len")
28
+ ("else{")
29
+ ("c=r.pos+l")
30
+ ("if(c>r.len)")
31
+ ("throw RangeError(\"index out of range\")")
32
+ ("l=r.len")
33
+ ("r.len=c")
34
+ ("}")
35
+ ("m=new this.ctor")
26
36
  ("while(r.pos<c){")
27
37
  ("var t=r.uint32()")
28
38
  ("if(t===e)")
@@ -40,7 +50,10 @@ function decoder(mtype) {
40
50
  if (field.map) { gen
41
51
  ("if(%s===util.emptyObject)", ref)
42
52
  ("%s={}", ref)
43
- ("var c2 = r.uint32()+r.pos");
53
+ ("var c2=r.uint32()+r.pos")
54
+ ("if(c2>r.len)")
55
+ ("throw RangeError(\"index out of range\")")
56
+ ("r.len=c2");
44
57
 
45
58
  if (types.defaults[field.keyType] !== undefined) gen
46
59
  ("k=%j", types.defaults[field.keyType]);
@@ -70,7 +83,10 @@ function decoder(mtype) {
70
83
  ("r.skipType(tag2&7,n)")
71
84
  ("break")
72
85
  ("}")
73
- ("}");
86
+ ("}")
87
+ ("if(r.pos!==c2)")
88
+ ("throw RangeError(\"index out of range\")")
89
+ ("r.len=c");
74
90
 
75
91
  if (types.long[field.keyType] !== undefined) gen
76
92
  ("%s[typeof k===\"object\"?util.longToHash(k):k]=value", ref);
@@ -92,8 +108,14 @@ function decoder(mtype) {
92
108
  if (types.packed[type] !== undefined) gen
93
109
  ("if((t&7)===2){")
94
110
  ("var c2=r.uint32()+r.pos")
111
+ ("if(c2>r.len)")
112
+ ("throw RangeError(\"index out of range\")")
113
+ ("r.len=c2")
95
114
  ("while(r.pos<c2)")
96
115
  ("%s.push(r.%s())", ref, type)
116
+ ("if(r.pos!==c2)")
117
+ ("throw RangeError(\"index out of range\")")
118
+ ("r.len=c")
97
119
  ("}else");
98
120
 
99
121
  // Non-packed
@@ -121,6 +143,13 @@ function decoder(mtype) {
121
143
  ("}")
122
144
  ("}");
123
145
 
146
+ gen
147
+ ("if(l!==undefined){")
148
+ ("if(r.pos!==c)")
149
+ ("throw RangeError(\"index out of range\")")
150
+ ("r.len=l")
151
+ ("}");
152
+
124
153
  // Field presence
125
154
  for (i = 0; i < mtype._fieldsArray.length; ++i) {
126
155
  var rfield = mtype._fieldsArray[i];
package/src/parse.js CHANGED
@@ -678,6 +678,9 @@ function parse(source, root, options) {
678
678
  }
679
679
 
680
680
  while (token !== "=") {
681
+ if (token === null) {
682
+ throw illegal(token, "end of input");
683
+ }
681
684
  if (token === "(") {
682
685
  var parensValue = next();
683
686
  skip(")");
package/src/reader.js CHANGED
@@ -78,6 +78,20 @@ Reader.create = create();
78
78
 
79
79
  Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;
80
80
 
81
+ function readVarint32NearEnd(reader) {
82
+ // Safely read up to four bytes of a varint32 near the reader limit
83
+ var value = 0;
84
+ for (var i = 0; i < 4; ++i) {
85
+ if (reader.pos >= reader.len)
86
+ throw indexOutOfRange(reader);
87
+ var b = reader.buf[reader.pos++];
88
+ value = (value | (b & 127) << i * 7) >>> 0;
89
+ if (b < 128)
90
+ return value;
91
+ }
92
+ throw indexOutOfRange(reader);
93
+ }
94
+
81
95
  /**
82
96
  * Reads a varint as an unsigned 32 bit value.
83
97
  * @function
@@ -86,6 +100,12 @@ Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore ne
86
100
  Reader.prototype.uint32 = (function read_uint32_setup() {
87
101
  var value = 4294967295; // optimizer type-hint, tends to deopt otherwise (?!)
88
102
  return function read_uint32() {
103
+ if (this.len - this.pos < 5) {
104
+ if (this.pos >= this.len)
105
+ throw indexOutOfRange(this);
106
+ if (this.buf[this.pos] >= 128)
107
+ return readVarint32NearEnd(this);
108
+ }
89
109
  value = ( this.buf[this.pos] & 127 ) >>> 0; if (this.buf[this.pos++] < 128) return value;
90
110
  value = (value | (this.buf[this.pos] & 127) << 7) >>> 0; if (this.buf[this.pos++] < 128) return value;
91
111
  value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; if (this.buf[this.pos++] < 128) return value;
package/src/wrappers.js CHANGED
@@ -40,6 +40,10 @@ var Message = require("./message"),
40
40
  wrappers[".google.protobuf.Any"] = {
41
41
 
42
42
  fromObject: function(object, depth) {
43
+ if (depth === undefined)
44
+ depth = 0;
45
+ if (depth > util.recursionLimit)
46
+ throw Error("max depth exceeded");
43
47
 
44
48
  // unwrap value type if mapped
45
49
  if (object && object["@type"]) {
@@ -57,7 +61,7 @@ wrappers[".google.protobuf.Any"] = {
57
61
  }
58
62
  return this.create({
59
63
  type_url: type_url,
60
- value: type.encode(type.fromObject(object, depth === undefined ? 1 : depth + 1)).finish()
64
+ value: type.encode(type.fromObject(object, depth + 1)).finish()
61
65
  });
62
66
  }
63
67
  }