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.
@@ -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
  */
@@ -171,12 +171,32 @@ Reader.prototype.raw = function read_raw(start, end) {
171
171
  return this.buf.subarray(start, end);
172
172
  };
173
173
 
174
+ function readVarint32NearEnd(reader) {
175
+ // Safely read up to four bytes of a varint32 near the reader limit
176
+ var value = 0;
177
+ for (var i = 0; i < 4; ++i) {
178
+ if (reader.pos >= reader.len)
179
+ throw indexOutOfRange(reader);
180
+ var b = reader.buf[reader.pos++];
181
+ value = (value | (b & 127) << i * 7) >>> 0;
182
+ if (b < 128)
183
+ return value;
184
+ }
185
+ throw indexOutOfRange(reader);
186
+ }
187
+
174
188
  /**
175
189
  * Reads a varint as an unsigned 32 bit value.
176
190
  * @function
177
191
  * @returns {number} Value read
178
192
  */
179
193
  Reader.prototype.uint32 = function read_uint32() {
194
+ if (this.len - this.pos < 5) {
195
+ if (this.pos >= this.len)
196
+ throw indexOutOfRange(this);
197
+ if (this.buf[this.pos] >= 128)
198
+ return readVarint32NearEnd(this);
199
+ }
180
200
  var buf = this.buf,
181
201
  pos = this.pos,
182
202
  value = (buf[pos] & 127) >>> 0;
@@ -227,6 +247,12 @@ Reader.prototype.uint32 = function read_uint32() {
227
247
  * @returns {number} Tag read
228
248
  */
229
249
  Reader.prototype.tag = function read_tag() {
250
+ if (this.len - this.pos < 5) {
251
+ if (this.pos >= this.len)
252
+ throw indexOutOfRange(this);
253
+ if (this.buf[this.pos] >= 128)
254
+ return readVarint32NearEnd(this);
255
+ }
230
256
  var buf = this.buf,
231
257
  pos = this.pos,
232
258
  value = (buf[pos] & 127) >>> 0;
@@ -472,9 +498,22 @@ Reader.prototype.double = function read_double() {
472
498
  */
473
499
  Reader.prototype.uint32s = function read_uint32s(array) {
474
500
  if (array === undefined) array = [];
475
- var end = this.uint32() + this.pos;
476
- while (this.pos < end)
477
- array.push(this.uint32());
501
+ var end = this.uint32() + this.pos, len = this.len, buf = this.buf, pos = this.pos, value;
502
+ if (end > len) throw indexOutOfRange(this, end - this.pos);
503
+ this.len = end;
504
+ while (pos < end) {
505
+ value = buf[pos++];
506
+ if (value < 128)
507
+ array.push(value);
508
+ else {
509
+ this.pos = pos - 1;
510
+ array.push(this.uint32());
511
+ pos = this.pos;
512
+ }
513
+ }
514
+ this.pos = pos;
515
+ if (pos !== end) throw RangeError("index out of range");
516
+ this.len = len;
478
517
  return array;
479
518
  };
480
519
 
@@ -485,9 +524,22 @@ Reader.prototype.uint32s = function read_uint32s(array) {
485
524
  */
486
525
  Reader.prototype.int32s = function read_int32s(array) {
487
526
  if (array === undefined) array = [];
488
- var end = this.uint32() + this.pos;
489
- while (this.pos < end)
490
- array.push(this.int32());
527
+ var end = this.uint32() + this.pos, len = this.len, buf = this.buf, pos = this.pos, value;
528
+ if (end > len) throw indexOutOfRange(this, end - this.pos);
529
+ this.len = end;
530
+ while (pos < end) {
531
+ value = buf[pos++];
532
+ if (value < 128)
533
+ array.push(value);
534
+ else {
535
+ this.pos = pos - 1;
536
+ array.push(this.int32());
537
+ pos = this.pos;
538
+ }
539
+ }
540
+ this.pos = pos;
541
+ if (pos !== end) throw RangeError("index out of range");
542
+ this.len = len;
491
543
  return array;
492
544
  };
493
545
 
@@ -498,9 +550,13 @@ Reader.prototype.int32s = function read_int32s(array) {
498
550
  */
499
551
  Reader.prototype.sint32s = function read_sint32s(array) {
500
552
  if (array === undefined) array = [];
501
- var end = this.uint32() + this.pos;
553
+ var end = this.uint32() + this.pos, len = this.len;
554
+ if (end > len) throw indexOutOfRange(this, end - this.pos);
555
+ this.len = end;
502
556
  while (this.pos < end)
503
557
  array.push(this.sint32());
558
+ if (this.pos !== end) throw RangeError("index out of range");
559
+ this.len = len;
504
560
  return array;
505
561
  };
506
562
 
@@ -511,9 +567,22 @@ Reader.prototype.sint32s = function read_sint32s(array) {
511
567
  */
512
568
  Reader.prototype.bools = function read_bools(array) {
513
569
  if (array === undefined) array = [];
514
- var end = this.uint32() + this.pos;
515
- while (this.pos < end)
516
- array.push(this.bool());
570
+ var end = this.uint32() + this.pos, len = this.len, buf = this.buf, pos = this.pos, value;
571
+ if (end > len) throw indexOutOfRange(this, end - this.pos);
572
+ this.len = end;
573
+ while (pos < end) {
574
+ value = buf[pos++];
575
+ if (value < 128)
576
+ array.push(value !== 0);
577
+ else {
578
+ this.pos = pos - 1;
579
+ array.push(this.bool());
580
+ pos = this.pos;
581
+ }
582
+ }
583
+ this.pos = pos;
584
+ if (pos !== end) throw RangeError("index out of range");
585
+ this.len = len;
517
586
  return array;
518
587
  };
519
588
 
@@ -632,9 +701,13 @@ Reader.prototype.doubles = function read_doubles(array) {
632
701
  */
633
702
  Reader.prototype.uint64s = function read_uint64s(array) {
634
703
  if (array === undefined) array = [];
635
- var end = this.uint32() + this.pos;
704
+ var end = this.uint32() + this.pos, len = this.len;
705
+ if (end > len) throw indexOutOfRange(this, end - this.pos);
706
+ this.len = end;
636
707
  while (this.pos < end)
637
708
  array.push(this.uint64());
709
+ if (this.pos !== end) throw RangeError("index out of range");
710
+ this.len = len;
638
711
  return array;
639
712
  };
640
713
 
@@ -645,9 +718,13 @@ Reader.prototype.uint64s = function read_uint64s(array) {
645
718
  */
646
719
  Reader.prototype.int64s = function read_int64s(array) {
647
720
  if (array === undefined) array = [];
648
- var end = this.uint32() + this.pos;
721
+ var end = this.uint32() + this.pos, len = this.len;
722
+ if (end > len) throw indexOutOfRange(this, end - this.pos);
723
+ this.len = end;
649
724
  while (this.pos < end)
650
725
  array.push(this.int64());
726
+ if (this.pos !== end) throw RangeError("index out of range");
727
+ this.len = len;
651
728
  return array;
652
729
  };
653
730
 
@@ -658,9 +735,13 @@ Reader.prototype.int64s = function read_int64s(array) {
658
735
  */
659
736
  Reader.prototype.sint64s = function read_sint64s(array) {
660
737
  if (array === undefined) array = [];
661
- var end = this.uint32() + this.pos;
738
+ var end = this.uint32() + this.pos, len = this.len;
739
+ if (end > len) throw indexOutOfRange(this, end - this.pos);
740
+ this.len = end;
662
741
  while (this.pos < end)
663
742
  array.push(this.sint64());
743
+ if (this.pos !== end) throw RangeError("index out of range");
744
+ this.len = len;
664
745
  return array;
665
746
  };
666
747
 
@@ -2563,7 +2644,6 @@ function pool(alloc, slice, size) {
2563
2644
  * @namespace
2564
2645
  */
2565
2646
  var utf8 = exports,
2566
- replacementChar = "\ufffd",
2567
2647
  looseDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
2568
2648
  strictDecoder;
2569
2649
  var TEXT_DECODER_MIN_LENGTH = 64;
@@ -2598,31 +2678,6 @@ utf8.length = function utf8_length(string) {
2598
2678
  return len;
2599
2679
  };
2600
2680
 
2601
- function utf8_read_js(buffer, start, end, str) {
2602
- for (var i = start; i < end;) {
2603
- var t = buffer[i++];
2604
- if (t <= 0x7F) {
2605
- str += String.fromCharCode(t);
2606
- } else if (t >= 0xC0 && t < 0xE0) {
2607
- var c2 = (t & 0x1F) << 6 | buffer[i++] & 0x3F;
2608
- str += c2 >= 0x80 ? String.fromCharCode(c2) : replacementChar;
2609
- } else if (t >= 0xE0 && t < 0xF0) {
2610
- var c3 = (t & 0xF) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
2611
- str += c3 >= 0x800 ? String.fromCharCode(c3) : replacementChar;
2612
- } else if (t >= 0xF0) {
2613
- var t2 = (t & 7) << 18 | (buffer[i++] & 0x3F) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
2614
- if (t2 < 0x10000 || t2 > 0x10FFFF)
2615
- str += replacementChar;
2616
- else {
2617
- t2 -= 0x10000;
2618
- str += String.fromCharCode(0xD800 + (t2 >> 10));
2619
- str += String.fromCharCode(0xDC00 + (t2 & 0x3FF));
2620
- }
2621
- }
2622
- }
2623
- return str;
2624
- }
2625
-
2626
2681
  function utf8_read_decoder(decoder, buffer, start, end) {
2627
2682
  var source = start === 0 && end === buffer.length
2628
2683
  ? buffer
@@ -2657,14 +2712,14 @@ utf8.read = function utf8_read_loose(buffer, start, end) {
2657
2712
  c7 = buffer[i + 6];
2658
2713
  c8 = buffer[i + 7];
2659
2714
  if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
2660
- return utf8_read_js(buffer, i, end, str);
2715
+ return str + utf8_read_decoder(looseDecoder, buffer, i, end);
2661
2716
  str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
2662
2717
  }
2663
2718
 
2664
2719
  for (; i < end; ++i) {
2665
2720
  c1 = buffer[i];
2666
2721
  if (c1 & 0x80)
2667
- return utf8_read_js(buffer, i, end, str);
2722
+ return str + utf8_read_decoder(looseDecoder, buffer, i, end);
2668
2723
  str += String.fromCharCode(c1);
2669
2724
  }
2670
2725
 
@@ -2775,7 +2830,7 @@ function Writer() {
2775
2830
  * Backing buffer.
2776
2831
  * @type {Uint8Array}
2777
2832
  */
2778
- this.buf = this.constructor.alloc(64);
2833
+ this.buf = this.constructor.alloc(Writer.initialBufferSize);
2779
2834
 
2780
2835
  /**
2781
2836
  * Cached DataView over {@link Writer#buf}.
@@ -2790,6 +2845,12 @@ function Writer() {
2790
2845
  this.states = null;
2791
2846
  }
2792
2847
 
2848
+ /**
2849
+ * Initial backing buffer size in bytes. Defaults to 128.
2850
+ * @type {number}
2851
+ */
2852
+ Writer.initialBufferSize = 128;
2853
+
2793
2854
  /**
2794
2855
  * Current write position.
2795
2856
  * @name Writer#len