Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Adding files preserving mode or mtime results in data corruption #4093

Closed
kstuart opened this issue May 11, 2022 · 4 comments
Closed

Adding files preserving mode or mtime results in data corruption #4093

kstuart opened this issue May 11, 2022 · 4 comments
Assignees
Labels
help wanted Seeking public contribution on this issue kind/bug A bug in existing code (including security flaws) kind/maybe-in-helia need/analysis Needs further analysis before proceeding P2 Medium: Good to have, but can wait until someone steps up

Comments

@kstuart
Copy link

kstuart commented May 11, 2022

Linux ce937568e283 5.17.5-arch1-1 #1 SMP PREEMPT Wed, 27 Apr 2022 20:56:11 +0000 x86_64 Linux

js-ipfs version: 0.15.2-0078aad85f92d7bc8e3a22eb9ef8efd257b439b5
interface-ipfs-core version: ^0.155.0
ipfs-http-client version: 1.0.0
Repo version: 12
System version: x64/linux
Node.js version: v16.4.2
Commit: 0078aad

jsipfs run in daemon offline mode

Steps to reproduce with --preserve-mtime (empty file)

touch -d@1652299617 /tmp/empty_file
jsipfs add --preserve-mtime /tmp/empty_file
added QmcrCRhLSqsroGBX2PyBtdCrKWBDxjgPpATLg3KxMqywna empty_file

jsipfs files stat /ipfs/QmcrCRhLSqsroGBX2PyBtdCrKWBDxjgPpATLg3KxMqywna
QmcrCRhLSqsroGBX2PyBtdCrKWBDxjgPpATLg3KxMqywna
Size: 6
CumulativeSize: 22
ChildBlocks: 0
Type: file
Mode: -rw-r--r--
Mtime: May 11, 2022, 08:06:57 PM UTC

jsipfs get QmcrCRhLSqsroGBX2PyBtdCrKWBDxjgPpATLg3KxMqywna
Saving file(s) QmcrCRhLSqsroGBX2PyBtdCrKWBDxjgPpATLg3KxMqywna

xxd QmcrCRhLSqsroGBX2PyBtdCrKWBDxjgPpATLg3KxMqywna
00000000: 0a04 0802 1800 ......

Expected:

The file 'QmcrCRhLSqsroGBX2PyBtdCrKWBDxjgPpATLg3KxMqywna' to have size 0 and contain no data.


Steps to reproduce with --preserve-mode (file with content)

echo -n "A" > /tmp/test_file
touch -d@1652299617 /tmp/test_file
jsipfs add --preserve-mode /tmp/test_file

added QmW198BawsGUvwKQN8hxUHKdCNSS3fYf7pMmPQujUAJnBH test_file

jsipfs files stat /ipfs/QmW198BawsGUvwKQN8hxUHKdCNSS3fYf7pMmPQujUAJnBH
QmW198BawsGUvwKQN8hxUHKdCNSS3fYf7pMmPQujUAJnBH
Size: 9
CumulativeSize: 17
ChildBlocks: 0
Type: file
Mode: -rw-r--r--
Mtime:

jsipfs get QmW198BawsGUvwKQN8hxUHKdCNSS3fYf7pMmPQujUAJnBH
Saving file(s) QmW198BawsGUvwKQN8hxUHKdCNSS3fYf7pMmPQujUAJnBH

xxd QmW198BawsGUvwKQN8hxUHKdCNSS3fYf7pMmPQujUAJnBH
00000000: 0a07 0802 1201 4118 01 ......A..

xxd /tmp/test_file
00000000: 41 A

Expected:

The file 'QmW198BawsGUvwKQN8hxUHKdCNSS3fYf7pMmPQujUAJnBH' to have size 1 and its content to exactly match /tmp/test_file.

@kstuart kstuart added the need/triage Needs initial labeling and prioritization label May 11, 2022
@BigLep BigLep added P2 Medium: Good to have, but can wait until someone steps up and removed need/triage Needs initial labeling and prioritization labels Jun 10, 2022
@BigLep
Copy link
Contributor

BigLep commented Jun 10, 2022

2022-06-10 conversation: there are two things to look into:

  1. Why js-ipfs is returning a non-zero size
  2. Why the CIDs are different

Maintainers agree this needs to get looked into. There isn't an estimate yet on when this will get picked up though given other priorities. Is this blocking for you @kstuart on your work?

@BigLep BigLep added the need/author-input Needs input from the original author label Jun 10, 2022
@github-actions
Copy link
Contributor

Oops, seems like we needed more information for this issue, please comment with more details or this issue will be closed in 7 days.

@kstuart kstuart changed the title Possible incorrect CID generated when preserving file attributes Adding files preserving mode or mtime results in data corruption Jun 22, 2022
@kstuart
Copy link
Author

kstuart commented Jun 22, 2022

@BigLep no, this doesn't block me. After further investigation I've updated the issue, note that preserving mode or mtime will add erroneous file data to the node, essentially a corruption of the original file.

@lidel lidel added kind/bug A bug in existing code (including security flaws) need/analysis Needs further analysis before proceeding help wanted Seeking public contribution on this issue and removed need/author-input Needs input from the original author labels Jun 24, 2022
@ipfs ipfs deleted a comment from welcome bot Jun 24, 2022
@whizzzkid
Copy link

js-ipfs is being deprecated in favor of Helia. You can follow the migration plan here #4336 and read the migration guide.

Please feel to reopen with any comments before 2023-06-05. We will do a final pass on reopened issues afterward (see #4336).

This issue might be resolved in Helia, if not, please let us know!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Seeking public contribution on this issue kind/bug A bug in existing code (including security flaws) kind/maybe-in-helia need/analysis Needs further analysis before proceeding P2 Medium: Good to have, but can wait until someone steps up
Projects
No open projects
Status: Done
Development

No branches or pull requests

4 participants