From 5fab77fb578b73fe5541999fca115c4710ebbac3 Mon Sep 17 00:00:00 2001 From: Erik Grinaker Date: Thu, 2 Jul 2020 16:00:26 +0200 Subject: [PATCH] proof: fix panic for keys with all 0xff bytes (#288) Fixes #286. The `cpIncr()` function incorrectly incremented all bytes for values that are all `0xff` before appending `0x00`. In these cases it should keep the original value and append `0x00`. --- CHANGELOG.md | 4 ++++ util.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0bede5c7..549b51192 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ - [\#312](https://github.com/cosmos/iavl/pull/312) Added `MutableTree.SetInitialVersion()` to set the initial version after tree initialization. +### Bug Fixes + +- [\#288](https://github.com/cosmos/iavl/pull/288) Fix panics when generating proofs for keys that are all `0xFF`. + ## 0.14.0 (July 2, 2020) **Important information:** the pruning functionality introduced with IAVL 0.13.0 via the options diff --git a/util.go b/util.go index 537e5a74f..adb3aa7b0 100644 --- a/util.go +++ b/util.go @@ -72,6 +72,9 @@ func cpIncr(bz []byte) (ret []byte) { } ret[i] = byte(0x00) if i == 0 { + // here, the original bz is all 0xFF, so we keep the original and append 0x00 + // instead of returning all 0x00 + ret = cp(bz) return append(ret, 0x00) } }