hypercore 11.13.1 → 11.13.2

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/lib/replicator.js CHANGED
@@ -30,7 +30,7 @@ const ReceiverQueue = require('./receiver-queue')
30
30
  const HotswapQueue = require('./hotswap-queue')
31
31
  const RemoteBitfield = require('./remote-bitfield')
32
32
  const { MerkleTree } = require('./merkle-tree')
33
- const { REQUEST_CANCELLED, REQUEST_TIMEOUT, INVALID_CAPABILITY, SNAPSHOT_NOT_AVAILABLE } = require('hypercore-errors')
33
+ const { REQUEST_CANCELLED, REQUEST_TIMEOUT, INVALID_CAPABILITY, SNAPSHOT_NOT_AVAILABLE, ASSERTION } = require('hypercore-errors')
34
34
  const m = require('./messages')
35
35
  const caps = require('./caps')
36
36
 
@@ -1235,13 +1235,20 @@ class Peer {
1235
1235
 
1236
1236
  _hasTreeParent (index) {
1237
1237
  if (this.remoteLength >= this.core.state.length) return true
1238
+ if (!(index >= 0)) throw ASSERTION('bad index to _hasTreeParent: ' + index)
1238
1239
 
1239
1240
  const ite = flatTree.iterator(index * 2)
1240
1241
 
1241
1242
  let span = 2
1242
1243
  let length = 0
1244
+ let cnt = 0
1243
1245
 
1244
1246
  while (true) {
1247
+ if (++cnt >= 64) {
1248
+ throw ASSERTION('_hasTreeParent is stuck, index=' + index + ', length=' + length +
1249
+ ', span=' + span + ', remoteLength=' + this.remoteLength + ', length=' + this.core.state.length)
1250
+ }
1251
+
1245
1252
  ite.parent()
1246
1253
 
1247
1254
  const left = (ite.index - ite.factor / 2 + 1) / 2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.13.1",
3
+ "version": "11.13.2",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {