@cryptotaxi247 / kubo / commits / c0ec37726

pin: Guard against callers causing refcount underflow

This used to lead to large refcount numbers, causing Flush to create a lot of IPFS objects, and merkledag to consume tens of gigabytes of RAM. License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Tommi Virtanen committed May 31, 2015 at 15:47 UTC c0ec3772698fd7eed226e273a46386bc2b2d8308
1 file changed +4
pin/indirect.go
+4
@@ -57,6 +57,10 @@ func (i *indirectPin) Increment(k key.Key) {
57 }
58
59 func (i *indirectPin) Decrement(k key.Key) {
60 + if i.refCounts[k] == 0 {
61 + log.Warningf("pinning: bad call: asked to unpin nonexistent indirect key: %v", k)
62 + return
63 + }
64 c := i.refCounts[k] - 1
65 i.refCounts[k] = c
66 if c <= 0 {