hypercore 11.13.0 → 11.13.1

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.
Files changed (2) hide show
  1. package/lib/merkle-tree.js +15 -0
  2. package/package.json +1 -1
@@ -679,6 +679,7 @@ class MerkleTree {
679
679
  // TODO: we could prop use a read batch here and do this in blocks of X for perf
680
680
  while (!ite.contains(head) && !(await hasTreeNode(session.storage, ite.index))) {
681
681
  cnt++
682
+ if (cnt >= 1024) throw ASSERTION('Bad arguments to missingNodes index=' + index + ' at length=' + length)
682
683
  ite.parent()
683
684
  }
684
685
 
@@ -742,6 +743,7 @@ function getByteOffsetBatch (roots, index, rx) {
742
743
  if ((index & 1) === 1) index = flat.leftSpan(index)
743
744
 
744
745
  let head = 0
746
+ let cnt = 0
745
747
 
746
748
  const promises = []
747
749
 
@@ -756,6 +758,8 @@ function getByteOffsetBatch (roots, index, rx) {
756
758
  const ite = flat.iterator(node.index)
757
759
 
758
760
  while (ite.index !== index) {
761
+ if (++cnt >= 1024) throw ASSERTION('Bad getByteOffsetSession index=' + index)
762
+
759
763
  if (index < ite.index) {
760
764
  ite.leftChild()
761
765
  } else {
@@ -930,8 +934,10 @@ async function seekTrustedTree (session, root, bytes, padding) {
930
934
  if (!bytes) return root
931
935
 
932
936
  const ite = flat.iterator(root)
937
+ let cnt = 0
933
938
 
934
939
  while ((ite.index & 1) !== 0) {
940
+ if (++cnt >= 1024) throw ASSERTION('Bad seekTrusted bytes=' + bytes + ', paddding=' + padding)
935
941
  const l = await getTreeNodeFromStorage(session.storage, ite.leftChild())
936
942
 
937
943
  if (l) {
@@ -972,11 +978,13 @@ async function seekUntrustedTree (session, root, bytes, padding) {
972
978
 
973
979
  function seekProof (session, rx, seekRoot, root, p) {
974
980
  const ite = flat.iterator(seekRoot)
981
+ let cnt = 0
975
982
 
976
983
  p.seek = []
977
984
  p.seek.push(getTreeNodeOrError(rx, ite.index))
978
985
 
979
986
  while (ite.index !== root) {
987
+ if (++cnt >= 1024) throw ASSERTION('Bad seekProof seekRoot=' + seekRoot + ', root=' + root)
980
988
  ite.sibling()
981
989
  p.seek.push(getTreeNodeOrError(rx, ite.index))
982
990
  ite.parent()
@@ -987,11 +995,13 @@ function blockAndSeekProof (session, rx, node, seek, seekRoot, root, p) {
987
995
  if (!node) return seekProof(session, rx, seekRoot, root, p)
988
996
 
989
997
  const ite = flat.iterator(node.index)
998
+ let cnt = 0
990
999
 
991
1000
  p.node = []
992
1001
  if (!node.value) p.node.push(getTreeNodeOrError(rx, ite.index))
993
1002
 
994
1003
  while (ite.index !== root) {
1004
+ if (++cnt >= 1024) throw ASSERTION('Bad blockAndSeekProof seekRoot=' + seekRoot + ', root=' + root)
995
1005
  ite.sibling()
996
1006
 
997
1007
  if (seek && ite.contains(seekRoot) && ite.index !== seekRoot) {
@@ -1017,10 +1027,13 @@ function upgradeProof (session, rx, node, seek, from, to, subTree, p) {
1017
1027
 
1018
1028
  const root = ite.index
1019
1029
  const target = from - 2
1030
+ let cnt = 0
1020
1031
 
1021
1032
  ite.seek(target)
1022
1033
 
1023
1034
  while (ite.index !== root) {
1035
+ if (++cnt >= 1024) throw ASSERTION('Bad upgradeProof target=' + target + ', root=' + root)
1036
+
1024
1037
  ite.sibling()
1025
1038
  if (ite.index > target) {
1026
1039
  if (p.node === null && p.seek === null && ite.contains(subTree)) {
@@ -1064,10 +1077,12 @@ function additionalUpgradeProof (session, rx, from, to, p) {
1064
1077
 
1065
1078
  const root = ite.index
1066
1079
  const target = from - 2
1080
+ let cnt = 0
1067
1081
 
1068
1082
  ite.seek(target)
1069
1083
 
1070
1084
  while (ite.index !== root) {
1085
+ if (++cnt >= 1024) throw ASSERTION('Bad arguments to additionalUpgradeProof root=' + root + ' target=' + target)
1071
1086
  ite.sibling()
1072
1087
  if (ite.index > target) {
1073
1088
  p.additionalUpgrade.push(getTreeNodeOrError(rx, ite.index))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.13.0",
3
+ "version": "11.13.1",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {