Repository navigation
txdb: handle malformed first coin cursor key - #35191
ArtSabintsev wants to merge 1 commit into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35191. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste |
|
utACK c02c4ae Reviewed the diff. This makes the initial |
| i->pcursor->GetKey(entry); | ||
| i->keyTmp.first = entry.key; | ||
| } else { | ||
| CoinEntry entry(&i->keyTmp.second); |
There was a problem hiding this comment.
A slight change in behavior is that the entry is created even if the cursor is invalid. Other versions where this is not the case:
if (i->pcursor->Valid() && (CoinEntry entry(&i->keyTmp.second); i->pcursor->GetKey(entry))) {
i->keyTmp.first = entry.key;
} else {
i->keyTmp.first = 0; // Make sure Valid() and GetKey() return false
}
if (i->pcursor->Valid()) {
CoinEntry entry(&i->keyTmp.second);
if (i->pcursor->GetKey(entry)) {
i->keyTmp.first = entry.key;
} else {
i->keyTmp.first = 0; // Make sure Valid() and GetKey() return false
}
} else {
i->keyTmp.first = 0; // Make sure Valid() and GetKey() return false
}
The latter is more verbose, but more readable and less error prone for future changes, does not relay on early exit conditional evaluation, and is closest to the original.
Please comment, consider. (Note: untested code.)
|
Thanks, but LLM output is not accepted if the author can not properly explain, test or could have written the change themselves. The bottleneck in this project has always been review and testing, not writing code. Development here is intentionally conservative and slow, and reviewer attention is the scarcest resource we have. LLMs have made this worse, anyone can now prompt them and post their output as PRs. There is an infinite amount plausible looking "improvements" for LLMs to suggest and work on. Unless we fully trust LLMs to both write and review code, humans still have to spend time understanding the proposed changes, which incurs a non-zero cost for every opened PR. I understand that contributing to this project can be intimidating, and using LLMs may seem tempting, but it really creates more issues for this project than it solves. The best way to help this project, is to review and test changes. You can use LLMs for this, but you shouldn't solely rely on them, or just post their output. Please reconsider whether it's something you genuinely think the project should pursue, independent of what your LLM suggested. I'll close this for now. |
Fixes #35172.
What?
CCoinsViewDB::Cursor()caches the first coin key after seeking into the chainstate DB. If the firstDB_COINentry is malformed,CDBIterator::GetKey()returns false, but the cursor warmup path ignored that return value.Because
CoinEntrydefaults its key marker toDB_COIN, a malformed key like justCcould leave the cursor reportingValid() == trueandGetKey() == trueeven though the key was not decoded.This makes the warmup path match
CCoinsViewDBCursor::Next(): if the iterator is invalid or the key cannot be decoded, invalidate the cached key.Scenario
This would require an already-corrupted or manually modified local chainstate LevelDB where the first coin key is readable by LevelDB but not decodable as a
CoinEntry.Normal node operation should not create this key shape, so this is a correctness/hardening fix rather than a common user-facing issue.
Testing
The regression test writes a single-byte
Ckey, which enters theDB_COINkeyspace but is too short to decode as aCoinEntry. It then reopens the DB throughCCoinsViewDBand checks that the returned cursor is invalid.