From cc5359e0634afa5b83071cfce010eab75f7a0b93 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Tue, 25 Feb 2025 15:10:13 +0800 Subject: [PATCH] core: fix integer divide by zero in function ValidateHeaderChain --- core/headerchain.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/headerchain.go b/core/headerchain.go index 5f6553e24d..af64b5cb95 100644 --- a/core/headerchain.go +++ b/core/headerchain.go @@ -233,14 +233,18 @@ func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header, checkFreq int) // Generate the list of seal verification requests, and start the parallel verifier seals := make([]bool, len(chain)) - for i := 0; i < len(seals)/checkFreq; i++ { - index := i*checkFreq + hc.rand.Intn(checkFreq) - if index >= len(seals) { - index = len(seals) - 1 + if checkFreq != 0 { + // In case of checkFreq == 0 all seals are left false. + for i := 0; i < len(seals)/checkFreq; i++ { + index := i*checkFreq + hc.rand.Intn(checkFreq) + if index >= len(seals) { + index = len(seals) - 1 + } + seals[index] = true } - seals[index] = true + // Last should always be verified to avoid junk + seals[len(seals)-1] = true } - seals[len(seals)-1] = true // Last should always be verified to avoid junk abort, results := hc.engine.VerifyHeaders(hc, chain, seals) defer close(abort)