Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Fix mem access violation merkleblock #9980
Conversation
laanwj
added Bug Tests
labels
Mar 13, 2017
|
If it shouldn't happen, maybe an |
|
@TheBlueMatt what was the behavior before if the elements list was empty? |
|
wait no that's @sipa |
|
nvm it returned 0 so this maintains the original behavior |
|
Probably best to assert that vTxid has non-zero length, as that would represent generating a tree for an invalid block. |
|
Changed to what @dcousens and @TheBlueMatt suggested. I think that makes sense at the end of the day. Also, from what I can tell, that assert cannot be hit from the p2p code. |
|
I would have set |
|
Looks good. Lightly tested ACK 51802cc if you're adding an assert, can you put some commenting in explaining the assumptions that you're testing (either around the assert or the function declaration). Also please remove the merge commits from this PR. EDIT: cool that this was found using your property-based testing. I've been meaning to review #8469 for a while. |
|
@jnewbery Addressed the concerns you had. If you want to chat about 8469 don't be afraid to ping me on irc. I think it will allow us to streamline testing AND exhaustively test invariants better than we are now. |
|
why no just setting |
|
@NicolasDorier - I had the same concerns as you, so I spent some time reading around the code to convince myself that this was ok. This code is only called from the CMerkleBlock constructor, which is only called from the gettxoutproof RPC or in response to a MSG_FILTERED_BLOCK getdata request. In both cases, we're constructing the Merkle Block from a block that's already in our mapBlockIndex. Therefore to hit this assert, we'd need there to be an invalid block in the mapBlockIndex, which would mean:
in which case, asserting is appropriate. As for concerns about future code calling this without knowing about the assert - they'd have to be constructing a merkle block for a block that they hadn't already validated, which is a very bad idea! Just to make sure, Chris has now also added a comment above the assert to clarify assumptions. Hope that allays your concerns! |
|
utACK bbdd771, though it would be nice to add a comment to CMerkleBlock noting that the block containing transactions will be asserted-on. |
|
@TheBlueMatt Added the comment, is this ready for merge? EDIT: Also rebased |
| @@ -121,6 +121,8 @@ class CPartialMerkleTree | ||
| /** | ||
| * Used to relay blocks as header + vector<merkle branch> | ||
| * to filtered nodes. | ||
| + * | ||
| + * NOTE: This is asserted on when building CPartialMerkleTree |
|
utACK 8276e70 |
|
utACK 8276e70 |
sipa
merged commit 8276e70
into
bitcoin:master
Jul 17, 2017
1 check passed
sipa
added a commit
that referenced
this pull request
Jul 17, 2017
|
|
sipa |
fee0d80
|
Christewart commentedMar 12, 2017
Fixing a possible memory access violation in CPartialMerkleTree::CalcHash().
This can happen if we some how a merkle tree with zero txids. I don't think this can happen in practice as we only send merkle block messages on the p2p network as of now -- we cannot receive them.
This was found with #8469, specifically using this generator which will cause a memory access violation on this test case.