multiformats / ruby-multihash

A simple multihash (https://github.com/multiformats/multihash) implementation for ruby.
MIT License
22 stars 13 forks source link

Length is a varint, can be multiple bytes #9

Closed andrew closed 1 year ago

andrew commented 3 years ago

I just ran into this whilst implementing myself and testing on some very long cids.

As outlined in https://github.com/multiformats/multihash#format, the length is a protobuf-style varint (in fact the hash function code is too but I've not seen any codes longer than a single byte), so in some cases the digest ends up being wrong.

Location where length is currently calculated: https://github.com/multiformats/ruby-multihash/blob/master/lib/multihashes.rb#L21

Example failing multihash:

z45btRgLsWtUjnxUC6eCo1EWfquee6nzwdLPDGyM7YAjiZHn6iArvVr546aaCXwsinDV7pLuzx3CfM7KiAXqf9CcqjjfVU9g4toFd9VE7VMASTrxDYWCzohasmJy1CbGhoArqQp5PyNPC6SBMYMqPQsGuUNXAtEBphybn9xRw3q9U7uyw77gMz3RzRSCo5D7nd6F3KcoQYuxD6NoGuqFuYoE2PHhZLksDd5StdH2a69WEWF2Y9RP1ZMZ5igg8XZH6DREV3h3

I'll try and find some time to put a pull request together tomorrow for this.

rvagg commented 1 year ago

closing due to inactivity, archiving repo