Skip to content

[Bug] P2P FetchInvDataMsgHandler and InventoryMsgHandler accept empty hash lists and bypass validation / rate limiting #7128

Backlog

Description

@FinchAlex

Description

In the latest release GreatVoyage-v4.8.2.4 (also present on master and develop, following #6712 and #6851), both FetchInvDataMsgHandler.check() and InventoryMsgHandler.check() validate duplicate hashes and unknown InventoryType, but neither rejects messages with an empty hashList (ids count == 0).

In production mainnet observations, anomalous inbound peers periodically send empty FetchInvDataMessage packets (ids = [], e.g., every ~300-350ms) without receiving any prior INV from the local node, and are neither rejected nor rate-limited.

Affected Code

  1. framework/src/main/java/org/tron/core/net/messagehandler/FetchInvDataMsgHandler.java (lines 142-216):

    • check() (line 158): hashList.size() != new HashSet<>(hashList).size() evaluates 0 != 0 as false and passes.
    • invType == InventoryType.TRX (lines 169-183):
      • The for (Sha256Hash hash : fetchInvDataMsg.getHashList()) loop runs 0 times, bypassing peer.getAdvInvSpread() membership validation.
      • tronInTrxFetchInvDataElement.getCount(10) counts elements (0 per empty packet), so high-frequency empty packets never trigger flood detection.
    • invType == InventoryType.BLOCK (lines 142-153, 185-192):
      • isAdvInv() loops 0 times over the empty list and returns true, which skips the entire if (!isAdv) block (including peer.isNeedSyncFromUs() and peer.getP2pRateLimiter().tryAcquire(...)).
  2. framework/src/main/java/org/tron/core/net/messagehandler/InventoryMsgHandler.java (lines 58-70):

    • check() similarly validates duplicates (hashList.size() != new HashSet<>(hashList).size()) and InventoryType, without rejecting hashList.isEmpty().

Impact

  • Malformed or malicious peers can send unlimited empty FETCH_INV_DATA / INVENTORY messages without triggering P2pException(TypeEnum.BAD_MESSAGE) or P2P rate limiting, consuming peerWorker thread CPU and allocating temporary collections (HashSet, ArrayList) on every packet.
  • There is no valid protocol reason for a peer to send an empty Inventory or FetchInvData message.

Expected Behavior

Reject empty hashList in both FetchInvDataMsgHandler.check() and InventoryMsgHandler.check() with P2pException(TypeEnum.BAD_MESSAGE, ...):

// FetchInvDataMsgHandler.java
List<Sha256Hash> hashList = fetchInvDataMsg.getHashList();
if (hashList.isEmpty()) {
  throw new P2pException(TypeEnum.BAD_MESSAGE, "FetchInvData hash list is empty");
}
// InventoryMsgHandler.java
List<Sha256Hash> hashList = inventoryMessage.getHashList();
if (hashList.isEmpty()) {
  throw new P2pException(TypeEnum.BAD_MESSAGE, "Inventory hash list is empty");
}

Activity

  1. FinchAlex commented on Nov 26, 2026

    @FinchAlex
    Author

    Follow-up to #7123 (release_v4.8.3).

    #7123 cleanly closes the empty-payload bypass in FetchInvDataMsgHandler.check(), bringing it in line with SyncBlockChainMsgHandler and ChainInventoryMsgHandler. However, the remaining two list-based P2P message handlers on release_v4.8.3 still accept empty payloads without throwing BAD_MESSAGE:

    1. InventoryMsgHandler.check() (framework/src/main/java/org/tron/core/net/messagehandler/InventoryMsgHandler.java, lines 56-70):

      • Validates duplicate hashes (hashList.size() != new HashSet<>(hashList).size()) and InventoryType, but does not reject hashList.isEmpty().
      • Because P2pEventHandlerImpl.checkInvRateLimit() (lines 220-245) counts msg.getInventory().getIdsCount() (which is 0 for an empty message), a peer can send unlimited empty INVENTORY packets (TRX or BLOCK) while completely bypassing the 10-second rate limit and never triggering BAD_PROTOCOL.
    2. TransactionsMsgHandler.check() (framework/src/main/java/org/tron/core/net/messagehandler/TransactionsMsgHandler.java, lines 150-170):

      • Iterates over msg.getTransactions().getTransactionsList() without checking list.isEmpty().
      • An empty TransactionsMessage (transactions = []) executes 0 loop iterations, bypassing the unsolicited-transaction check (peer.getAdvInvRequest().containsKey(item)), allowing a peer to send unlimited empty TRXS packets without disconnection.

    Suggested Fix

    Align both handlers with #7123 (FetchInvDataMsgHandler), SyncBlockChainMsgHandler, and ChainInventoryMsgHandler by rejecting empty lists as BAD_MESSAGE:

    // InventoryMsgHandler.java (in check())
    List<Sha256Hash> hashList = inventoryMessage.getHashList();
    if (hashList.isEmpty()) {
      throw new P2pException(TypeEnum.BAD_MESSAGE, "Inventory ids is empty");
    }
    // TransactionsMsgHandler.java (in check())
    List<Transaction> list = msg.getTransactions().getTransactionsList();
    if (list.isEmpty()) {
      throw new P2pException(TypeEnum.BAD_MESSAGE, "Transactions list is empty");
    }
  2. 317787106 commented on Nov 26, 2026

    @317787106
    Collaborator

    @FinchAlex Thansk for your remind. It will be fixed in v4.8.3, see this #7129.

  3. halibobo1205 commented on Nov 26, 2026

    @halibobo1205
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions