Replace comparison of a bytes element to the string literal "\0" with an integer 0 in linearize-data.py to ensure correct behavior in Python 3. In Python 3, indexing a bytes object returns an integer, not a single-character string, so the previous comparison would always be false. This change improves compatibility and correctness of the script when detecting end-of-file or null bytes.
fix: Python 3 bytes comparison in linearize-data.py #32978
pull Galoretka wants to merge 1 commits into bitcoin:master from Galoretka:fix/python3-bytes-comparison-linearize-data changing 1 files +1 −1-
Galoretka commented at 3:50 PM on July 15, 2025: none
-
e38b7f3575
fix: Python 3 bytes comparison in linearize-data.py
Replace comparison of a bytes element to the string literal "\0" with an integer 0 in linearize-data.py to ensure correct behavior in Python 3. In Python 3, indexing a bytes object returns an integer, not a single-character string, so the previous comparison would always be false. This change improves compatibility and correctness of the script when detecting end-of-file or null bytes.
-
DrahtBot commented at 3:50 PM on July 15, 2025: contributor
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--006a51241073e994b41acfe9ec718e94-->
Code Coverage & Benchmarks
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32978.
<!--021abf342d371248e50ceaed478a90ca-->
Reviews
See the guideline for information on the review process. A summary of reviews will appear here.
<!--5faf32d7da4f0f540f40219e4f7537a3-->
-
maflcko commented at 4:38 PM on July 15, 2025: member
Are there steps to reproduce, or a test to confirm the fix?
-
Galoretka commented at 6:15 PM on July 15, 2025: none
Are there steps to reproduce, or a test to confirm the fix?
The change is necessary because, in Python 3, indexing a bytes object returns an integer, not a single-character string. For example:
b"\0"[0] == "\0" # always False in Python 3 b"\0"[0] == 0 # TrueSo, the previous comparison would never detect a null byte as intended.
-
maflcko commented at 6:17 PM on July 15, 2025: member
I was asking about an end-to-end test, like test/functional/feature_loadblock.py or by calling linearize-data.py manually
- Galoretka closed this on Jul 16, 2025