#36157 contrib: fix dead null-byte check in linearize-data.py

full analysis

https://github.com/bitcoin/bitcoin/pull/36157 · aman21-droid · +1/-1 in 1 files, 1 commits · labels: Scripts and tools

Goal

  • Prevent linearize-data.py from hanging indefinitely on zero-padded block files
  • Ensure the script cleanly finishes or advances to the next file instead of looping forever

Fixes a Python 2 to 3 migration bug in `contrib/linearize/linearize-data.py` where indexing a `bytes` object was compared against a string (`"\0"`) rather than an integer (`0`). This dead check prevented detecting the end of block files with null-byte padding, causing the script to hang in an infinite read loop.

Problem: Users running `linearize-data.py` against block directories where files end with preallocated zero padding (such as pruned nodes or unfinished files) encounter an indefinite hang instead of cleanly moving to the next file or exiting.

Category: Tools and scripts (#14 of 22)

P3 · bug fix

  • P3 because it resolves an infinite read loop in a niche offline utility
  • The tool has a limited user base so this is routine maintenance rather than an urgent fix

Fixes a definite hang in a contrib utility script with a clear reproduction step. As aman21-droid explains, 'Indexing a bytes object returns an int in Python 3, so inhdr[0] == "\0" is always false and the zero-padding check never fires.' Because linearize is a niche offline tool, this is worthwhile maintenance rather than a release blocker.

Membership: Modifies `contrib/linearize/linearize-data.py`, an offline script under contrib.

Factors: security/stability 0, bug 2, performance 0, user value 1, leverage 0

Reviewability: Ready

  • Ready for review
  • Clean one-line fix with a straightforward reproduction step

Clean one-line diff with an easy reproduction step and no pending questions.

Author status: active

Agreement: Crickets

  • No reviews or comments yet
  • Recently opened PR awaiting initial feedback

No reviews or comments yet.

The PR was opened recently and has received no feedback so far.

Review verdicts (DrahtBot): 0

Files

2 lines under test/bench/ci.

  • contrib/linearize/linearize-data.py +1/-1

Card

This PR fixes a bug in contrib/linearize/linearize-data.py where comparing an indexed byte to a string ('\0' instead of 0) caused an infinite loop on block files ending in zero padding. The issue reliably hangs the script when reading unfinalized block files or when reading pruned datadirs. It is a one-line bug fix with a provided reproduction, currently awaiting initial review.

Data

dossier JSON · extract JSON · model openrouter/google/gemini-3.8-flash, generated 2026-09-17T15:58, confidence high, input hash 91ab488ad1f63c61