Skip to content

fix(bits): prevent BitArray.UnmarshalJSON from crashing on 0 bits in the JSON (backport #2774)#2780

Merged
melekes merged 4 commits intov0.34.xfrom
mergify/bp/v0.34.x/pr-2774
Apr 16, 2024
Merged

fix(bits): prevent BitArray.UnmarshalJSON from crashing on 0 bits in the JSON (backport #2774)#2780
melekes merged 4 commits intov0.34.xfrom
mergify/bp/v0.34.x/pr-2774

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented Apr 11, 2024

This change fixes a bug in which BitArray.UnmarshalJSON hadn't accounted for the fact that invoking NewBitArray(<=0) returns nil and hence when dereferenced would crash with a runtime nil pointer dereference. This bug was found by my security analysis and fuzzing too.

Author: @odeke-em

Fixes #2658


PR checklist

  • Tests written/updated
  • Changelog entry added in .changelog (we use unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments
  • Title follows the Conventional Commits spec

This is an automatic backport of pull request #2774 done by [Mergify](https://mergify.com).

…the JSON (#2774)

This change fixes a bug in which BitArray.UnmarshalJSON hadn't accounted
for the fact that invoking NewBitArray(<=0) returns nil and hence when
dereferenced would crash with a runtime nil pointer dereference. This
bug was found by my security analysis and fuzzing too.

Author: @odeke-em

Fixes #2658

---

#### PR checklist

- [x] Tests written/updated
- [x] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code
comments~~
- [x] Title follows the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec

---------

Co-authored-by: Emmanuel T Odeke <emmanuel@orijtech.com>
(cherry picked from commit 75d12c3)

# Conflicts:
#	.changelog/v0.34.32/bug-fixes/2774-bitarray-unmarshal-json.md
@mergify mergify bot requested a review from a team as a code owner April 11, 2024 09:17
@mergify mergify bot added the conflicts label Apr 11, 2024
@mergify
Copy link
Contributor Author

mergify bot commented Apr 11, 2024

Cherry-pick of 75d12c3 has failed:

On branch mergify/bp/v0.34.x/pr-2774
Your branch is up to date with 'origin/v0.34.x'.

You are currently cherry-picking commit 75d12c32b.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   libs/bits/bit_array.go
	modified:   libs/bits/bit_array_test.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	added by them:   .changelog/v0.34.32/bug-fixes/2774-bitarray-unmarshal-json.md

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@melekes melekes self-assigned this Apr 11, 2024
@melekes melekes merged commit f4e7974 into v0.34.x Apr 16, 2024
@melekes melekes deleted the mergify/bp/v0.34.x/pr-2774 branch April 16, 2024 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants