Add empty vector check before xdr_get in HerderPersistenceImpl::getQuorumSet#5230
Draft
Add empty vector check before xdr_get in HerderPersistenceImpl::getQuorumSet#5230
Conversation
…orumSet Add a guard to check if the decoded quorum set bytes vector is empty before constructing xdr_get with &vec.front()/&vec.back()+1. Without this check, calling front()/back() on an empty vector is undefined behavior in C++. If a corrupted database row contains an empty blob, the code now throws a descriptive runtime_error instead of proceeding with UB. This matches the existing pattern in LedgerHeaderUtils.cpp. Agent-Logs-Url: https://github.com/stellar/stellar-core/sessions/5f91013f-7cd3-40f0-9039-c541ad3e93b2 Co-authored-by: marta-lokhova <9428003+marta-lokhova@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
marta-lokhova
April 16, 2026 23:30
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
HerderPersistenceImpl::getQuorumSetdecodes a base64 quorum set blob from the database into astd::vector<uint8_t>and then constructsxdr::xdr_getusing&qSetBytes.front()/&qSetBytes.back() + 1without checking whether the decoded vector is empty. If a corrupted database row contains an empty string, evaluatingfront()andback()on an empty vector is undefined behavior in C++.This adds an empty-vector guard that throws a descriptive
std::runtime_errorbefore the UB can occur, matching the identical pattern already established inLedgerHeaderUtils::decodeFromData(line 111-114 ofLedgerHeaderUtils.cpp).Details
The only unguarded site using the
&vec.front()/&vec.back() + 1pattern was inHerderPersistenceImpl.cpp:369. Other database read paths either:LedgerHeaderUtils.cpp)xdr::xdr_from_opaque()which internally uses.data()/.data() + .size()and is safe for empty vectorsTesting
Database corruptions should not happen in practice, so this is a defensive guard. The change is a simple 5-line conditional that throws before any pointer dereference, consistent with existing error handling in the codebase.