hypercore 10.37.27 → 10.37.28
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/audit.js +6 -0
- package/package.json +1 -1
package/lib/audit.js
CHANGED
|
@@ -3,6 +3,8 @@ const flat = require('flat-tree')
|
|
|
3
3
|
const c = require('compact-encoding')
|
|
4
4
|
const b4a = require('b4a')
|
|
5
5
|
|
|
6
|
+
const empty = b4a.alloc(32)
|
|
7
|
+
|
|
6
8
|
// this is optimised for speed over mem atm
|
|
7
9
|
// can be tweaked in the future
|
|
8
10
|
|
|
@@ -33,6 +35,8 @@ module.exports = async function auditCore (core) {
|
|
|
33
35
|
const leftNode = getNode(left)
|
|
34
36
|
const rightNode = getNode(right)
|
|
35
37
|
|
|
38
|
+
if (!rightNode && !leftNode) continue
|
|
39
|
+
|
|
36
40
|
stack.push(leftNode, rightNode)
|
|
37
41
|
|
|
38
42
|
if (valid[node.index]) {
|
|
@@ -93,9 +97,11 @@ module.exports = async function auditCore (core) {
|
|
|
93
97
|
return corrections
|
|
94
98
|
|
|
95
99
|
function getNode (index) {
|
|
100
|
+
if (index * 40 + 40 > tree.byteLength) return null
|
|
96
101
|
const state = { start: index * 40, end: index * 40 + 40, buffer: tree }
|
|
97
102
|
const size = c.uint64.decode(state)
|
|
98
103
|
const hash = c.fixed32.decode(state)
|
|
104
|
+
if (size === 0 && hash.equals(empty)) return null
|
|
99
105
|
return { index, size, hash }
|
|
100
106
|
}
|
|
101
107
|
|