bucket: add count guard for branch pages in Stats#1171
Conversation
Bucket.Stats() panics with index-out-of-range when iterating branch pages with zero elements. The leaf page path has a Count() != 0 guard, but the branch page path accesses BranchPageElement(Count() - 1) without one. Wrap the branch element access in the same guard. Fixes etcd-io#1170 Signed-off-by: Quoc Bui <buiviquoc@gmail.com>
|
Please also add a changelog item under https://github.com/etcd-io/bbolt/blob/main/CHANGELOG/CHANGELOG-1.5.md#boltdb, thx |
Correct, we need to only add changelog items for 1.4 and. 1.3 instead. We need to backport the PR to 1.4 and 1.3.
Please feel free to backport the PR to 1.4 and 1.3 first, and update chanagelogs in a separate PR later. thx |
|
Sorry for the confusion. Please do not update changelog in this PR. Please follow my previous comment #1171 (comment) |
fad9692 to
386d5b6
Compare
|
/ok-to-test |
| // Add header and all element headers. | ||
| used := common.PageHeaderSize + (common.BranchPageElementSize * uintptr(p.Count()-1)) | ||
| used := common.PageHeaderSize | ||
| if p.Count() != 0 { |
There was a problem hiding this comment.
Note: normally a branch page should always have at least 1 item, otherwise the page will be removed. But the change has no any harm.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahrtr, quocvibui The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Bucket.Stats()panics with an index-out-of-range error when iterating branch pages with a zero element count. The leaf page path has ap.Count() != 0guard (line 628), but the branch page path accessesp.BranchPageElement(p.Count() - 1)without one — causing an underflow whenCount()is 0.This wraps the branch element access in the same guard pattern used for leaf pages.
Fixes #1170