Skip to content

contrib: makeseeds.py parseline() raises IndexError on lines with exactly 11 fields #36146

Closed
l0rinc/bitcoin
#290

Description

@amannx21

While reading through contrib/seeds/makeseeds.py I noticed parseline() can crash on a malformed line instead of skipping it.

The function checks that a line has enough columns:

if len(sline) < 11:
    # line too short to be valid, skip it.
    return None

but further down it does:

agent = sline[11][1:-1]

sline[11] is the 12th column, so a valid line actually needs 12 fields, not 11. A line with exactly 11 fields gets past the check and then throws IndexError. 11 is the highest index the function uses, so the check should be < 12.

Quick way to see it:

cd contrib/seeds
python -c "import makeseeds; makeseeds.parseline('1.2.3.4:8333 1 1700000000 100.00% 100.00% 100.00% 100.00% 100.00% 910001 000000000000040d 70016')"

9 and 10 fields return None like they should, 12 fields parse fine, only 11 crashes.

It takes down the whole run, because main() calls it in a list comprehension with no try/except:

Loading asmap database "asmap.dat"...Done.
Loading and parsing DNS seeds...Traceback (most recent call last):
  File "contrib/seeds/makeseeds.py", line 270, in <module>
    main()
  File "contrib/seeds/makeseeds.py", line 219, in main
    ips = [parseline(line) for line in lines]
           ^^^^^^^^^^^^^^^
  File "contrib/seeds/makeseeds.py", line 118, in parseline
    agent = sline[11][1:-1]
            ~~~~~^^^^
IndexError: list index out of range

Annoying because it happens after the asmap database is already loaded, so that work is wasted too.

Expected: an 11 field line should return None and get skipped, same as 9 and 10.

This isn't only theoretical. README.md builds seeds_main.txt by appending one crawler's output onto another's:

curl https://21.ninja/seeds.txt.gz | gzip -dc > seeds_main.txt
curl https://mainnet.achownodes.xyz/seeds.txt.gz | gzip -dc >> seeds_main.txt

so the file is a mix of two independently maintained formats, and a truncated download would leave a short last line as well. That's the case the check is there for.

There's no test covering makeseeds, so this isn't caught anywhere. Happy to open a PR with the fix and a test for it.

Seen on master@dc0395c5.

Activity

  1. l0rinc commented on Sep 2, 2026

    @l0rinc
    Contributor

    Concept ACK, the off by one seems real. Even if not noticed for the past decade, might be worth fixing it.

  2. amannx21 commented on Sep 2, 2026

    @amannx21
    ContributorAuthor

    ok than i will work on it and open a PR.

  3. fanquake commented on Sep 14, 2026

    @fanquake
    Member

    Closing for now, as I don't think we need an issue open for this, given a PR exists: #36151.

  4. added a commit that references this issue on Oct 5, 2026
    8c49a9a
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions