BMDSoftware / dicoogle-ipfs-storage

This is a Dicoogle plugin to support the storage of files over IPFS.
Other
14 stars 4 forks source link

Support CIDv1 #7

Open lidel opened 2 years ago

lidel commented 2 years ago

Summary

Heads up:

Problem

This code assumes every CID is CIDv0 (looks the same as Multihash, so it is parsed as Multihash here):

                    public InputStream getInputStream() throws IOException {
                        Multihash filePointer = Multihash.fromBase58(location.toString().replaceFirst("ipfs://", ""));

                        byte[] fileContents = new byte[0];
                        try {
                            fileContents = ipfs.cat(filePointer);
                        } catch (IOException e) {
                            logger.error("Failed to retrieve object", e);
                            return null;
                        }

Try parsing ipfs://bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi – it is not Base58 (it is CIDv1 in Base32), so will throw an exception.

Solution

Always assume localtion is a CID and parse it using a library that understands CIDv1.

You can use CID implementation from java-cid, you can also peek at how CIDs are used in Peergos

See:

Happy to answer any questions / guide

cc @rlebre for awareness

rlebre commented 2 years ago

Thank you very much for the heads up @lidel. I'll look into this soon and definitely reach you if a technical issue arises. Thanks!