Skip to content

Fix: from_reader() multibyte varint parsing#80

Open
sumanjeet0012 wants to merge 1 commit into
ipld:masterfrom
sumanjeet0012:fix-67
Open

Fix: from_reader() multibyte varint parsing#80
sumanjeet0012 wants to merge 1 commit into
ipld:masterfrom
sumanjeet0012:fix-67

Conversation

@sumanjeet0012

Copy link
Copy Markdown
Contributor

Closes #67

Description

This PR fixes an issue where from_reader() incorrectly parsed CIDv1 when dealing with multihash types or lengths that use multi-byte varints (e.g., blake2b-256 which has the code 0xB220).

Previously, the parsing logic assumed that the multihash code and digest length were always precisely 1 byte, leading to ValueError: Not enough data to read CIDv1 multihash when decoding multi-byte codes.

Changes

  • Imported varint to correctly decode varint integers incrementally from the stream.
  • Replaced the hardcoded single-byte array reading logic with varint.decode_stream by implementing an internal TrackingReader that properly counts bytes consumed.
  • This ensures full compatibility with CIDs containing any arbitrary multicodec and multihash varint combinations.

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.

from_reader() assumes single-byte varints — breaks for multi-byte codec codes

1 participant