Chia-Network / bladebit

A high-performance k32-only, Chia (XCH) plotter supporting in-RAM and disk-based plotting
Apache License 2.0
337 stars 106 forks source link

Fix crashing when writing C tables with -b 512 #251

Closed AlexGuo1998 closed 1 year ago

AlexGuo1998 commented 1 year ago

See https://github.com/Chia-Network/bladebit/issues/249#issuecomment-1313442568 for explanation

harold-b commented 1 year ago

Pasting the PR summary here from @AlexGuo1998 ( https://github.com/Chia-Network/bladebit/issues/249#issuecomment-1313442568):

After digging into the code I assume this is a bug.

https://github.com/Chia-Network/bladebit/blob/9fac46aff0476e829d476412de18497a3a2f7ed8/src/plotdisk/k32/CTableWriterBounded.h#L305-L306

https://github.com/Chia-Network/bladebit/blob/9fac46aff0476e829d476412de18497a3a2f7ed8/src/plotdisk/MapWriter.h#L192-L198

Length of _mapBitCounts should be _numBuckets+ExtraBucket i.e. _numBuckets, 512. However it's defined as:

https://github.com/Chia-Network/bladebit/blob/9fac46aff0476e829d476412de18497a3a2f7ed8/src/plotdisk/k32/CTableWriterBounded.h#L355-L358

https://github.com/Chia-Network/bladebit/blob/9fac46aff0476e829d476412de18497a3a2f7ed8/src/plotdisk/DiskPlotConfig.h#L4

Oops.

Anything more than 256 buckets would crash, because uint32 _threadCount get overridden to an arbitrary large number, making jobs[i] pointing to an invalid address.

https://github.com/Chia-Network/bladebit/blob/9fac46aff0476e829d476412de18497a3a2f7ed8/src/threading/MTJob.h#L530-L534

harold-b commented 1 year ago

I reviewed it and you are correct, I appreciate the fix! I am surprised that it had worked before in local runs with this bug present.

harold-b commented 1 year ago

It seems the commit was made from master instead of the latest develop. Can you please rebase your commit from the latest develop instead of master since this is supposed to be merged into develop, I need the history to remain linear. Then do a push --force so that

AlexGuo1998 commented 1 year ago

done