-
Notifications
You must be signed in to change notification settings - Fork 37.8k
blockfilter: Avoid out-of-bounds script access. #14073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Concept ACK Very nice find @TheBlueMatt |
utACK 40a9c6c38c6aeaac83fe2639c9ac2d2b262296fc |
src/blockfilter.cpp
Outdated
@@ -208,7 +208,7 @@ static GCSFilter::ElementSet BasicFilterElements(const CBlock& block, | |||
for (const CTransactionRef& tx : block.vtx) { | |||
for (const CTxOut& txout : tx->vout) { | |||
const CScript& script = txout.scriptPubKey; | |||
if (script[0] == OP_RETURN) continue; | |||
if (script.size() > 0 && script[0] == OP_RETURN) continue; | |||
elements.emplace(script.begin(), script.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it looks like it adds size 0 entries to the filter, which is a violation of BIP158.
I believe this should be "script.size() < 1 ||". No?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit to @gmaxwell comment, script.empty() || ...
.
src/blockfilter.cpp
Outdated
@@ -208,7 +208,7 @@ static GCSFilter::ElementSet BasicFilterElements(const CBlock& block, | |||
for (const CTransactionRef& tx : block.vtx) { | |||
for (const CTxOut& txout : tx->vout) { | |||
const CScript& script = txout.scriptPubKey; | |||
if (script[0] == OP_RETURN) continue; | |||
if (script.size() > 0 && script[0] == OP_RETURN) continue; | |||
elements.emplace(script.begin(), script.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit to @gmaxwell comment, script.empty() || ...
.
src/test/blockfilter_tests.cpp
Outdated
@@ -67,6 +67,7 @@ BOOST_AUTO_TEST_CASE(blockfilter_basic_test) | |||
CMutableTransaction tx_2; | |||
tx_2.vout.emplace_back(300, included_scripts[2]); | |||
tx_2.vout.emplace_back(0, excluded_scripts[0]); | |||
tx_2.vout.emplace_back(600, included_scripts[5]); // Script is empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this should be excluded_scripts[2]
?
nit, above in L62 add something along
// This script is left empty.
// excluded_scripts[2];
Code change also avoids out-of-bounds script access bug.
utACK f055995. |
utACK |
re-utACK f055995 |
f055995 blockfilter: Omit empty scripts from filter contents. (Jim Posen) Pull request description: Caught during review of #12254 by @TheBlueMatt. #12254 (comment) Tree-SHA512: cfc9e3eeaba12a14fd3d2e1ccce1a1f89e8cf44cc340ceec05d2d5fa61d27ff64e355603f4ad2184ff73c0ed23dfdab6e2103bddc48f3b76cb13b88d428770ac
f055995 blockfilter: Omit empty scripts from filter contents. (Jim Posen) Pull request description: Caught during review of bitcoin#12254 by @TheBlueMatt. bitcoin#12254 (comment) Tree-SHA512: cfc9e3eeaba12a14fd3d2e1ccce1a1f89e8cf44cc340ceec05d2d5fa61d27ff64e355603f4ad2184ff73c0ed23dfdab6e2103bddc48f3b76cb13b88d428770ac
f055995 blockfilter: Omit empty scripts from filter contents. (Jim Posen) Pull request description: Caught during review of bitcoin#12254 by @TheBlueMatt. bitcoin#12254 (comment) Tree-SHA512: cfc9e3eeaba12a14fd3d2e1ccce1a1f89e8cf44cc340ceec05d2d5fa61d27ff64e355603f4ad2184ff73c0ed23dfdab6e2103bddc48f3b76cb13b88d428770ac
f055995 blockfilter: Omit empty scripts from filter contents. (Jim Posen) Pull request description: Caught during review of bitcoin#12254 by @TheBlueMatt. bitcoin#12254 (comment) Tree-SHA512: cfc9e3eeaba12a14fd3d2e1ccce1a1f89e8cf44cc340ceec05d2d5fa61d27ff64e355603f4ad2184ff73c0ed23dfdab6e2103bddc48f3b76cb13b88d428770ac
f055995 blockfilter: Omit empty scripts from filter contents. (Jim Posen) Pull request description: Caught during review of bitcoin#12254 by @TheBlueMatt. bitcoin#12254 (comment) Tree-SHA512: cfc9e3eeaba12a14fd3d2e1ccce1a1f89e8cf44cc340ceec05d2d5fa61d27ff64e355603f4ad2184ff73c0ed23dfdab6e2103bddc48f3b76cb13b88d428770ac
f055995 blockfilter: Omit empty scripts from filter contents. (Jim Posen) Pull request description: Caught during review of bitcoin#12254 by @TheBlueMatt. bitcoin#12254 (comment) Tree-SHA512: cfc9e3eeaba12a14fd3d2e1ccce1a1f89e8cf44cc340ceec05d2d5fa61d27ff64e355603f4ad2184ff73c0ed23dfdab6e2103bddc48f3b76cb13b88d428770ac
f055995 blockfilter: Omit empty scripts from filter contents. (Jim Posen) Pull request description: Caught during review of bitcoin#12254 by @TheBlueMatt. bitcoin#12254 (comment) Tree-SHA512: cfc9e3eeaba12a14fd3d2e1ccce1a1f89e8cf44cc340ceec05d2d5fa61d27ff64e355603f4ad2184ff73c0ed23dfdab6e2103bddc48f3b76cb13b88d428770ac
f055995 blockfilter: Omit empty scripts from filter contents. (Jim Posen) Pull request description: Caught during review of bitcoin#12254 by @TheBlueMatt. bitcoin#12254 (comment) Tree-SHA512: cfc9e3eeaba12a14fd3d2e1ccce1a1f89e8cf44cc340ceec05d2d5fa61d27ff64e355603f4ad2184ff73c0ed23dfdab6e2103bddc48f3b76cb13b88d428770ac
f055995 blockfilter: Omit empty scripts from filter contents. (Jim Posen) Pull request description: Caught during review of bitcoin#12254 by @TheBlueMatt. bitcoin#12254 (comment) Tree-SHA512: cfc9e3eeaba12a14fd3d2e1ccce1a1f89e8cf44cc340ceec05d2d5fa61d27ff64e355603f4ad2184ff73c0ed23dfdab6e2103bddc48f3b76cb13b88d428770ac
f055995 blockfilter: Omit empty scripts from filter contents. (Jim Posen) Pull request description: Caught during review of bitcoin#12254 by @TheBlueMatt. bitcoin#12254 (comment) Tree-SHA512: cfc9e3eeaba12a14fd3d2e1ccce1a1f89e8cf44cc340ceec05d2d5fa61d27ff64e355603f4ad2184ff73c0ed23dfdab6e2103bddc48f3b76cb13b88d428770ac
Caught during review of #12254 by @TheBlueMatt. #12254 (comment)