mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
univalue: respect token end pointer #35281
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35281
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-univalue-token-bounds"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #28260.
Avoid reading past the supplied end pointer in two places:
Also update the UniValue unit test and parse_univalue fuzz target to exercise bounded input.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
No conflicts as of last run.
why the
??🚧 At least one of the CI tasks failed.
Task
iwyu: https://github.com/bitcoin/bitcoin/actions/runs/25806359727/job/75815150297LLM reason (✨ experimental): CI failed because the IWYU (include-what-you-use) check flagged missing/wrong includes and intentionally returned non-zero exit status (“Failure generated from IWYU”).
Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
You're right, it's not needed. I fixed it in a new commit.
Would it be the case to add also few tests for fractions and exp numbers?
Added in commit 28f609c7bb — eight tests covering fractions, exponents, and combined, using the same size/end-pointer pattern as the existing tests in this function.
tACK 28f609c7bb78c233356470b9399c35b3183563a6
Thanks for the added tests.
One comment: my suggestion is to squash the two commits into a single one, as they do not seem to represent different logical steps.
Concept ACK
I think most of these unit tests are redundant however. Also not sure we should be introducing a new utility for this. I think the only cases actually adding a bit of coverage is the leading
-01case. Maybe that should just be covered by some more test fixture files?EDIT:
It would also be good to mention that this is fixing two separate out of bounds reads.
I would prefer if this used the more straight forward
std::string_view raw_view{raw, end}than doing pointer arithmetic.Is this really worthwhile? Seems like these kind of cases are better covered in the fuzz test anyway.
Isn't this covered in the test fixtures already?
Isn't this tested already in the fixture files?
@ferminquant can you respond to the review here? It's been a month.
Thanks for the review. Done in commit 7f633b3beaa7778d0e2dcc87b9cd2baf5490c939:
The focused UniValue test builds and passes locally.
Seems fine, but this should either be a correctly-sized buffer (without null-term), or it should be moved to a fixture file.
This should be a string view on a buffer, like in the fuzz test
can be removed as well, given the fuzz test, and the other tests.
Well, this is adding back the null-byte
Thanks, fixed in d107f950e8:
The focused UniValue test passes locally.
Either this needs to be copied into a fresh buffer (so that truly no data follows), or the tests need to be adjusted to not have trailing whitespace.
🐙 This pull request conflicts with the target branch and needs rebase.
@ferminquant this has been in need of a rebase for a while. Can you do so?
Base:
65896ac58ea63e29ad19d41b492e37f8722ac715Head:
045b0ef7b42d50975cedaa6deeb9a39c879af92f🟠 Major
Pass a length when constructing the string view (src/univalue/lib/univalue_read.cpp:101, head)
std::string_view{raw, end}is not a valid C++20 pointer-and-length construction becauseendis a pointer, not a size. Since this project requires C++20, the parser translation unit will not compile. Pass the remaining length as the second argument, for examplestatic_cast<std::size_t>(end - raw).💡 Suggestion
Make bounded-input regression assertions deterministic (src/univalue/test/unitester.cpp:177, head)
The exact-size arrays provide memory-checker coverage, but with the old checks restored, assertions may depend on bytes outside the arrays: keyword matching may see
nullaftern, and the-0check reads past its array. Keep these tests and add shorter views over fully initialized backing buffers. For example, a one-byte view ofnullmust fail, a two-byte view of-01must parse as-0, and a one-byte view of-backed by-xmust fail. These cases deterministically cover keyword matching, number lookahead, and thefirstDigit >= endguard.Review coverage was incomplete. The adversarial_glm review did not complete.
Full review report
@sedited Done, sorry for the delay.