]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.14] math/big: correct off-by-one access in divBasic
authorRémy Oudompheng <remyoudompheng@gmail.com>
Thu, 5 Mar 2020 06:59:00 +0000 (07:59 +0100)
committerAndrew Bonventre <andybons@golang.org>
Mon, 27 Apr 2020 16:42:55 +0000 (16:42 +0000)
commitcd65852feeef2e6e8d8c06bbf037bc4d6372e93d
tree9ad9109121a78d7fecf291882fce96d6cd603c70
parent768e5d1e4d079e1c941c154ae0397369567a5190
[release-branch.go1.14] math/big: correct off-by-one access in divBasic

The divBasic function computes the quotient of big nats u/v word by word.
It estimates each word qhat by performing a long division (top 2 words of u
divided by top word of v), looks at the next word to correct the estimate,
then perform a full multiplication (qhat*v) to catch any inaccuracy in the
estimate.

In the latter case, "negative" values appear temporarily and carries
must be carefully managed, and the recursive division refactoring
introduced a case where qhat*v has the same length as v, triggering an
out-of-bounds write in the case it happens when computing the top word
of the quotient.

Fixes #37501

Change-Id: I15089da4a4027beda43af497bf6de261eb792f94
Reviewed-on: https://go-review.googlesource.com/c/go/+/221980
Reviewed-by: Robert Griesemer <gri@golang.org>
(cherry picked from commit ac1fd419b6d2af8b0e69b13fa5c794705095db0a)
Reviewed-on: https://go-review.googlesource.com/c/go/+/227877
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/math/big/nat.go
src/math/big/nat_test.go