cbor-gen icon indicating copy to clipboard operation
cbor-gen copied to clipboard

WriteCid should fail if the Cid in question doesn't pass checks that would cause it to fail if read in ReadCid

Open wadealexc opened this issue 4 years ago • 0 comments

WriteCid accepts CIDs with length >= 1, writing a MajByteString with at least length 2: https://github.com/whyrusleeping/cbor-gen/blob/0b9f6c5fb1636544f94f5087817df99699de49ba/utils.go#L581-L588

The following requirements exist for ReadCid, but do not exist for WriteCid:

  • ReadCid errors if read length is over 512: https://github.com/whyrusleeping/cbor-gen/blob/0b9f6c5fb1636544f94f5087817df99699de49ba/utils.go#L550
  • ReadCid errors if first read byte is nonzero: https://github.com/whyrusleeping/cbor-gen/blob/0b9f6c5fb1636544f94f5087817df99699de49ba/utils.go#L568-L570
  • ReadCid errors if read bytes do not pass several checks in cid.Cast: https://github.com/whyrusleeping/cbor-gen/blob/0b9f6c5fb1636544f94f5087817df99699de49ba/utils.go#L572

wadealexc avatar Jan 15 '21 21:01 wadealexc