Skip to content

chore: filter empty multiaddrs in identify protocol#3479

Merged
tabcat merged 5 commits into
libp2p:mainfrom
dozyio:check-empty-multiaddr
May 16, 2026
Merged

chore: filter empty multiaddrs in identify protocol#3479
tabcat merged 5 commits into
libp2p:mainfrom
dozyio:check-empty-multiaddr

Conversation

@dozyio
Copy link
Copy Markdown
Collaborator

@dozyio dozyio commented Apr 24, 2026

Description

Add a check for empty multiaddrs from identify to stop them being added to the peer store.

Fixes #3478

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@dozyio dozyio marked this pull request as ready for review April 24, 2026 22:24
@dozyio dozyio requested a review from a team as a code owner April 24, 2026 22:24
tabcat added 2 commits May 12, 2026 22:49
Hoist the cleaned listenAddrs once and reuse it for both peer.addresses
and the returned IdentifyResult so peer:identify event consumers can't
crash on bare / or unparseable bytes. Fold the empty check into
getCleanMultiaddr so it returns undefined for zero-byte multiaddrs.
@tabcat
Copy link
Copy Markdown
Member

tabcat commented May 12, 2026

Issues:

  • result.listenAddrs at utils.ts:172 still used raw message.listenAddrs.map(buf => multiaddr(buf)), so peer:identify consumers and the return value of identify.identify() still surfaced bare / to anything that read them.
  • Malformed bytes would throw InvalidMultiaddrError at that same line after peerStore.patch had already run — partial-state failure, same crash class as fix(autonat-v2): spurious exceptions #3400.

Changes:

  • Hoisted the cleaned listenAddrs once and reused it for both peer.addresses and result.listenAddrs.
  • Folded the empty check into getCleanMultiaddr so it returns undefined for zero-byte multiaddrs too (also helps observedAddr in identify.ts:111).
  • Added a junk-byte (Uint8Array.from([0xff, 0xff, 0xff])) test case — the existing new Uint8Array(0) short-circuits in getCleanMultiaddr before reaching the try/catch.

@tabcat tabcat merged commit cc151e1 into libp2p:main May 16, 2026
46 of 48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiaddr "/" coming from peerStore

2 participants