-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Fix UBSan warnings triggered when loading corrupt mempool.dat files #19381
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
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.
Concept ACK, will review
Concept ACK: thanks for fixing! :)
Update: Negative deltas are allowed! |
@practicalswift I was thinking along the same line. Also, It seems better to initiate shutdown once something like this happens. As just returning So I made it to initiate shutdown if loadmempool fails. Not sure if that's strictly necessary, looking for suggestions here before I update the PR. The log
Also please give suggestions for a better error message. |
Update: Negative deltas are allowed! |
8cc8548
to
c58261d
Compare
@practicalswift updated to return failure instead of skipping |
Update: Negative deltas are allowed! |
@practicalswift silly me. Should have done that. will push the same. |
c58261d
to
f19dcd4
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
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.
ACK modulo nits
Could perhaps use a more descriptive PR title and commit message: what about something along the lines of "Fix UBSan warnings triggered when loading corrupt mempool.dat files"? :)
f19dcd4
to
069043e
Compare
@practicalswift addressed all your comments and rebased. |
@rajarshimaitra I think you still want
Update: Negative deltas allowed. Something along the lines of …
... and ...
Also, would you mind also updating the PR title to the more descriptive commit message? :)~~ |
src/validation.cpp
Outdated
pool.PrioritiseTransaction(i.first, i.second); | ||
if (!MoneyRange(i.second)) { | ||
return false; | ||
} else { |
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.
} else { |
nit: No need to change indentation on early-return. (same above)
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.
Sorry, I didn't get it. Can you explain a bit what are you suggesting here?
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.
This was fixed in your last push AFAICT :)
@practicalswift If i understand you correctly this is what you are suggesting?
and
Let me know if this seems correct. |
Update: Negative deltas are allowed! Also would you mind changing the PR title to |
069043e
to
2cc2cbd
Compare
Fixed and updated. |
Update: Negative deltas are allowed! Restarted Travis which failed spuriously :) |
Code review ACK 2cc2cbd |
if (!MoneyRange(amountdelta)) { | ||
return false; | ||
} |
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.
There is no requirement for deltas to be in MoneyRange
... Better use a numeric_limit max
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.
Before I push the commit does this look ok?
CAmount amountdelta = nFeeDelta;
if (amountdelta > numeric_limits<int64_t>::max() || amountdelta < numeric_limits<int64_t>::min()) {
return false;
}
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.
@luke-jr Oh, crap thanks for alerting about that! I naïvely assumed that the bounds of CAmount
were defined by MoneyRange(…)
, but I now understand that this is a case where negative amounts are allowed for a CAmount
. I assume the valid range here is [-MAX_MONEY, MAX_MONEY]
then?
Should CAmount
perhaps be reserved for cases where MoneyRange(…)
defines the bounds?
@rajarshimaitra I don't think that is what @luke-jr is suggesting: note that CAmount
is int64_t
so amountdelta
is guaranteed to be in the range you're checking for in the suggested diff ([std:: numeric_limits<int64_t>::min(), std:: numeric_limits<int64_t>::max()]
) :)
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.
Oh, right. Well, this sounds quite deep for my grasp and I wouldn't know what exactly to do. Do suggest and will update the PR accordingly.
@rajarshimaitra To allow for negative deltas: what about replacing the NODISCARD bool IsValidFeeDelta(const CAmount fee_delta) {
return fee_delta >= -MAX_MONEY && fee_delta <= MAX_MONEY;
} |
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
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.
Part of this patch is already in ee11a41. The other part I am not sure it fixes the issue. See also #20383 (comment)
if (amountdelta) { | ||
pool.PrioritiseTransaction(tx->GetHash(), amountdelta); | ||
} | ||
TxValidationState state; | ||
if (nTime + nExpiryTimeout > nNow) { | ||
if (nTime > nNow - nExpiryTimeout) { |
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.
Already in ee11a41
Closing due to inactivity |
This fixes some undefined behavior observed in the issue #19728.
The bugs can be reproduced by using corpus added here and the harness added in PR#19259