Skip to content

Fix Integer::is_zero to check entire value#94

Closed
sumleo wants to merge 2 commits intoNLnetLabs:mainfrom
sumleo:fix/integer-iszero
Closed

Fix Integer::is_zero to check entire value#94
sumleo wants to merge 2 commits intoNLnetLabs:mainfrom
sumleo:fix/integer-iszero

Conversation

@sumleo
Copy link
Copy Markdown

@sumleo sumleo commented Feb 15, 2026

Fixes incorrect is_zero() implementation that only checked the first byte, returning true for non-zero multi-byte integers starting with 0x00. Now correctly checks for single-byte zero.

Previously only checked first byte, incorrectly returning true for
multi-byte positive integers starting with 0x00 (e.g., 128u8 encodes
as [0x00, 0x80] but is not zero).

Now checks that the value is exactly one byte containing zero.
@partim
Copy link
Copy Markdown
Member

partim commented Mar 30, 2026

In BER encoding, multi-byte integers are not allowed to have the bits of the first octet be all zero or all one, i.e., they need to be encoded with the shortest possible number of octets. This is enforced by Integer::check_head. Therefore, just checking if the first octet is 0 when checking for zero.

@partim partim closed this Mar 30, 2026
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.

2 participants