Skip to content

Fix: decode multi-byte varints correctly in get_prefix - #62

Open
sumanjeet0012 wants to merge 1 commit into
multiformats:masterfrom
sumanjeet0012:fix-issue-46
Open

Fix: decode multi-byte varints correctly in get_prefix#62
sumanjeet0012 wants to merge 1 commit into
multiformats:masterfrom
sumanjeet0012:fix-issue-46

Conversation

@sumanjeet0012

@sumanjeet0012 sumanjeet0012 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Description

Closes #46.

This pull request addresses issue, where get_prefix was returning an incomplete/incorrect prefix for hash functions utilizing multi-byte varint codes (e.g., hash functions with codes > 0x7F like sha2-224, blake2b-*, etc.).

The original code assumed a hardcoded 2-byte prefix size, expecting exactly one byte for the code varint and exactly one byte for the length varint.

Proposed Changes

  • Updates get_prefix to properly decode both the hash code varint and the digest length varint from the input stream using BytesIO, guaranteeing accuracy regardless of varint length.
  • Adds test cases (test_get_prefix_multi_byte_code & test_get_prefix_type_error) ensuring accuracy against multi-byte codes (using sha2_224 as an example).

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.

get_prefix() hardcodes 2-byte prefix — breaks for multi-byte varint codes

1 participant