ipfs / boxo

A set of reference libraries for building IPFS applications and implementations in Go.
https://github.com/ipfs/boxo#readme
Other
213 stars 95 forks source link

Crash in sizeBelowThreshold #675

Open wenyue opened 1 month ago

wenyue commented 1 month ago

I found a bug that can cause a crash. In the directory sizeBelowThreshold function, we call the EnumLinksAsync function, then call parallelShardWalk, and the sizeBelowThreshold function may be end if we have already fetched enough shards to assert we are above the threshold. At this time, parallelShardWalk may still running the nextShard.walkChildren. Next, because sizeBelowThreshold has been completed, we can continue to modify direcotry. At this time, walkChildren will cause a crash because the hamt ds.childer has been modified.

An example is: Call direcotry.unlink(), and then immediately call direcotry.addChild(). If run many times, it may trigger a crash.

welcome[bot] commented 1 month ago

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review. In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment. Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

Finally, remember to use https://discuss.ipfs.io if you just need general support.

wenyue commented 1 month ago

This is my fix, please take a look. https://github.com/wenyue/boxo/commit/af6f2b055f545d06f1e4425b7fd718abdec21ad3

lidel commented 1 month ago

@wenyue are you willing to open a PR with the fix and a test?

Triage note: we will look into this in spare time.