Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object patch add-link overwrites root node data when child is too small #7190

Open
ellttBen opened this issue Apr 21, 2020 · 7 comments
Open
Assignees
Labels
effort/days Estimated to take multiple days, but less than a week exp/intermediate Prior experience is likely helpful kind/bug A bug in existing code (including security flaws) status/ready Ready to be worked

Comments

@ellttBen
Copy link

Version information:

go-ipfs version: 0.4.23-
Repo version: 7
System version: amd64/linux
Golang version: go1.13.7

Description:

Hello,

I was trying to add links to other versions of an image to the original's dag node. Though the links are working, accessing the root node yields a child version of the original image instead of the original.

To reproduce, we use two versions of the same image :

  • original : QmcFDihqvEwzgahFora3TU1BRZ84UJRSd2PW43j4buSs6n
  • smaller version : Qmapcp7ey9eUyk98eEK8iDbu7VdUHVtdd1RVsP5Wvqf4Cp

Then, we run

ipfs object patch add-link QmcFDihqvEwzgahFora3TU1BRZ84UJRSd2PW43j4buSs6n "small.jpg" Qmapcp7ey9eUyk98eEK8iDbu7VdUHVtdd1RVsP5Wvqf4Cp

On my machine, this yields QmQbr75jzhPXWFi59uRUrig6U2paGwfKSe8MLuDwC5s8VL.

We can then observe that the above cid doesn't display the original, but the small.jpg link works and yields the same image. In testing, I have noticed that when the small image is larger (my guess is larger than chunk size), this behavior disappears.

In case the images aren't available :

@ellttBen ellttBen added the kind/bug A bug in existing code (including security flaws) label Apr 21, 2020
ellttBen added a commit to ellttBen/go-unixfs that referenced this issue May 28, 2020
@Stebalien Stebalien added kind/enhancement A net-new feature or improvement to an existing feature and removed kind/bug A bug in existing code (including security flaws) labels Jun 22, 2020
@Stebalien
Copy link
Member

Sorry for the delay, this got lost in the noise.

The short version is that UnixFSv1 (the current go-ipfs filesystem format) simply doesn't support this. Unfortunately, adding support for this is rather difficult without introducing compatibility concerns.

The plan has always been to switch to a "v2" UnixFS based on CBOR objects but work on this has stalled for now.

@ellttBen
Copy link
Author

@Stebalien Thanks for taking the time to respond. I've opened another related issue on the go-unixfs repo (ipfs/boxo#390) in which I specify what I think would go into adding support for this feature. If my assumptions are correct, I have a fix ready and can open a PR right away. The proposed solution passes the tests from both repos and seems to fix the bug, if there's any interest.

@Stebalien
Copy link
Member

What's your proposal, specifically? The first step here would be to open a PR against the unixfs spec in https://github.com/ipfs/specs/.

@Stebalien
Copy link
Member

Ah, I see your proposal. That won't work, unfortunately. It'll work for tiny files that fit into one block, but how would you handle alternative versions for large files?

@ellttBen
Copy link
Author

ellttBen commented Jun 26, 2020

Reading back my explanation, I've failed to highlight the most important aspect : we should stop descending through the DAG when a node has only named links. This condition is expressed by the snippet len(node.Links()[0].Name) != 0, since I've noticed that empty links always come first, but this might be too much of a hack and it might be worth it to go through the entire node.Links() array.
I have tested the solution on root files that fit into one chunk as well as chunked files, all generated by go-ipfs, and it does seem to work. Sorry for the lack of clarity!

Also, I don't know how to translate this into a change of spec, since I've gone about it in the spirit of fixing an implementation bug.

@aschmahmann aschmahmann added exp/intermediate Prior experience is likely helpful kind/bug A bug in existing code (including security flaws) status/ready Ready to be worked effort/days Estimated to take multiple days, but less than a week and removed kind/enhancement A net-new feature or improvement to an existing feature labels Apr 12, 2021
@schomatis schomatis assigned schomatis and unassigned Stebalien Dec 23, 2021
@schomatis
Copy link
Contributor

Per @lidel:

I think if you see a way to throw an error instead of malforming the data, then its fine to fix it with one-liner PR. (Error could say "this api is deprecated, use MFS for now")

If it is more work, I'd say close the issue and pick up and redesign patching under ipfs dag patch (#4782) instead.

Will be working on dag patch and close this issue when it lands.

@BigLep
Copy link
Contributor

BigLep commented Mar 10, 2022

dag patch work is happening here: #4782

@BigLep BigLep added this to the Best Effort Track milestone Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/days Estimated to take multiple days, but less than a week exp/intermediate Prior experience is likely helpful kind/bug A bug in existing code (including security flaws) status/ready Ready to be worked
Projects
No open projects
Status: 🛑 Blocked
Development

No branches or pull requests

5 participants