Don't try to read SLE with key 0 from the ledger: #4351
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
High Level Overview of Change
Debug builds are occasionally hitting an
assert
at Ledger.cpp line 436 (see #4341). Theassert
is at least 8 years old and appears to still be relevant.Ledger::read
should not be called with an ID of 0.NFTokenAcceptOffer
transactions can be written (presumably incorrectly) in such a way that theNFTokenSellOffer
andNFTokenBuyOffer
fields can contain a 0 value. Thepreclaim
function for this transaction did not validate the value before callingLedger::read
.Note that this issue is not harmful in release builds. If an
assert
fails in a debug build, as it did in this case, it will stop the program. However,assert
s are not included in release builds, so they are skipped. In this case,Ledger::read
properly handles that case, and returns anullptr
if the ID is 0.NFTokenSellOffer::preclaim
checks thatnullptr
and correctly returnstecOBJECT_NOT_FOUND
, as it would if the transaction provided a valid ID which was not in the ledger.This fix preserves that functionality, but checks for 0 in
NFTokenSellOffer::preclaim
before callingLedger::read
, and returns the sametecOBJECT_NOT_FOUND
result. Thus, an amendment is not required.Type of Change