mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
compressor: reject oversized scripts during deserialization #36386
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!36386
Loading…
Reference in a new issue
No description provided.
Delete branch "l0rinc/script-compression-replace-oversized"
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?
Problem: UTXO insertion excludes scripts larger than
MAX_SCRIPT_SIZEas unspendable, so an oversized compressed script indicates corrupt data. Deserialization currently uses anOP_RETURNfallback and skips the oversized payload, hiding the corruption.Fix: Throw
std::ios_base::failureas soon as the decoded script length exceedsMAX_SCRIPT_SIZE.Context: #7933 added the fallback to avoid an out-of-memory failure in the then-current per-transaction chainstate format, when coin database deserialization errors were indistinguishable from missing entries. #34931 now sends coin deserialization failures to the fatal database-error path, and #24236 removed upgrade support for that old format.
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
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
🔵 Suggestion ·
ScriptCompressiondoes not explain its storage-only size limitScriptCompressiondocuments encoding larger scripts but omits the coin/undo invariant that makesUnser's new rejection a storage-corruption check rather than a limit on valid transaction outputs.Location:
src/compressor.h:89(head).Review coverage was incomplete.
Reviewed:
777ede538bfb· Review report · Previous reportspermalink
Not sure, reusing a destination would be an unrelated bug? So I am half suggesting to drop the test in a third commit again, or at least clarify in the comment that this isn't supposed to test any real production behavior.
lgtm either way.
We do have some existing reuses, e.g. in
github.com/bitcoin/bitcoin@e7aef7e86d/src/rpc/blockchain.cpp (L3435-L3462)the snapshot export reuses the sameCoinin the loop. Regardless, added a comment clarifying that this tests the fallback directly, since normal UTXO insertion excludes oversized scripts.Tested ACK
f313faff44I built test_bitcoin (GCC 13.3, RelWithDebInfo) and ran compress_tests on this and on
11494efb01. Both are clean. Puttingscript << OP_RETURNback makes compress_oversized_script fail, so the new check covers the fix.Concept ACK
f313faff44This has a bit too much happening at once IMO (+ redundant
CScript-ctor-call). Would rather have something closer tonit: Could verify that
restoredstarts out spendable before the compression round-trip makes it unspendable?Ralph suggested also pinning down the resulting script (#36386 (comment)), which seems fair enough.
Guess it could be done through:
tACK
426f29c3f1I decoded 1307 compressed scripts (raw sizes 0 to 39 and from just under
MAX_SCRIPT_SIZEto 200000, truncated streams, every special type) into a fresh target and five reused ones, a P2PKH among them, and compared each result with what a library I maintain decodes from the same bytes. On the base, every complete oversized script decoded into a reused target keeps the old bytes and appendsOP_RETURN(35 decodes). On this head every raw and oversized case matches for every target.One path still depends on the target: an uncompressed P2PK (type 4 or 5) whose x is not on the curve leaves a reused target untouched, so a P2PKH stays a P2PKH. #36280 makes that path throw. Its
compressor.hchange merges cleanly with this one; onlycompress_tests.cppconflicts. With both applied, no decode in the set depends on what the target held before. I can share the vectors and the test.ACK
426f29c3f1nit: Could compute at compile time:
review ACK
426f29c3f1🏉Show signature
Signature:
Reviewed, left some comments. Happy to re-check/ack once answered.
(
426f29c3f1)The commit message states: "so the result is independent of the destination's prior contents". However, this is not always the case. In this branch,
DecompressScriptcould fail in such a way that it does not modifyscript(in the0x04/0x05prefix + error case).Either adjust this codepath as well (reset it in case of error), or soften the claim.
Would it be possible to clear the
scriptoutput variable at the beginning of this method? That would ensure the claim (independence of previous value).I've just realized that #36280 addresses exactly this, so I think it's fine as it is in this PR.
ACK
426f29c3f1Upgraded my previous review result, upon reconsideration. This change is a net improvement, independent of #36280 . I'd appreciate answers to my comments, nonetheless.
Not sure why this should be changed from the motivation provided here. If I understand this correctly, the only way to encounter an oversized script outside of loadtxoutset is corruption. Why not just throw in that case? Deserializing potentially corrupt entries as unspendable seems confusing to me in the first place.
Even if this happens inside loadtxoutset, such a utxo-file is still only possible after corruption. While reviewing this I thought that this was needed to gracefully upgrade ancient utxo dbs, and looking at the diff of https://github.com/bitcoin/bitcoin/pull/7933, it seems that was accurate?
However, according to
git blame ./test/functional/feature_unsupported_utxo_db.pythose dbs are now invalid anyway, so throwing seems more consistent with other deser errors.I really hated that ugly, hacky
OP_RETURNfallback too. It seems to have been introduced as an OOM mitigation becauseCDBWrapper::Read()couldn't distinguish a missing entry from a deserialization failure, so throwing would have made the whole transaction's UTXO record look missing. The same decoder also remained part of the old per-transaction chainstate upgrade path, but #24236 removed that path and requires reindexing instead. Now that https://github.com/bitcoin/bitcoin/pull/34931 fixed the error handling for coin reads, we can indeed throw here, which is so much better in every sense. I've updated the PR accordingly. Thanks for the pushback!🚧 At least one of the CI tasks failed.
Task
Windows, test cross-built: https://github.com/bitcoin/bitcoin/actions/runs/46878258029/job/143457183354LLM reason (✨ experimental): functional_test_fail:
feature_unsupported_utxo_db.pyfailed while starting the node because parsing its RPC auth cookie raisedIndexError(split_userpass[1]was missing).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.
Intermittent network issues can occur; re-run CI for now, and report the issue if they keep happening.
A functional or integration test failure may be intermittent or unrelated to this pull request.
If no dedicated issue thread exists, create a new one to track it.
Leave a comment here, if you need help tracking down a confusing failure.