@colyseus/schema 3.0.64 → 3.0.66

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.
@@ -338,6 +338,10 @@ const _float64 = new Float64Array(_convoBuffer);
338
338
  const _uint64 = new BigUint64Array(_convoBuffer);
339
339
  const _int64 = new BigInt64Array(_convoBuffer);
340
340
  function utf8Read(bytes, it, length) {
341
+ // boundary check
342
+ if (length > bytes.length - it.offset) {
343
+ length = bytes.length - it.offset;
344
+ }
341
345
  var string = '', chr = 0;
342
346
  for (var i = it.offset, end = it.offset + length; i < end; i++) {
343
347
  var byte = bytes[i];
@@ -370,9 +374,10 @@ function utf8Read(bytes, it, length) {
370
374
  }
371
375
  continue;
372
376
  }
373
- console.error('Invalid byte ' + byte.toString(16));
374
377
  // (do not throw error to avoid server/client from crashing due to hack attemps)
375
378
  // throw new Error('Invalid byte ' + byte.toString(16));
379
+ console.error('decode.utf8Read(): Invalid byte ' + byte + ' at offset ' + i + '. Skip to end of string: ' + (it.offset + length));
380
+ break;
376
381
  }
377
382
  it.offset += length;
378
383
  return string;
@@ -1059,6 +1064,9 @@ class ChangeTree {
1059
1064
  if (typeof (this.ref[$childType]) !== "string") {
1060
1065
  // MapSchema / ArraySchema, etc.
1061
1066
  for (const [key, value] of this.ref.entries()) {
1067
+ if (!value) {
1068
+ continue;
1069
+ } // sparse arrays can have undefined values
1062
1070
  callback(value[$changes], this.indexes?.[key] ?? key);
1063
1071
  }
1064
1072
  }
@@ -3699,7 +3707,9 @@ class Schema {
3699
3707
  this[$changes].change(metadata[metadata[property]].index, operation);
3700
3708
  }
3701
3709
  clone() {
3702
- const cloned = new (this.constructor);
3710
+ // Create instance without calling custom constructor
3711
+ const cloned = Object.create(this.constructor.prototype);
3712
+ Schema.initialize(cloned);
3703
3713
  const metadata = this.constructor[Symbol.metadata];
3704
3714
  //
3705
3715
  // TODO: clone all properties, not only annotated ones