Skip to content

Conversation

@imsodin
Copy link
Member

@imsodin imsodin commented Sep 30, 2022

Untested so far.

@imsodin imsodin marked this pull request as ready for review September 30, 2022 22:13
@acolomb acolomb linked an issue Nov 7, 2022 that may be closed by this pull request
@acolomb
Copy link
Member

acolomb commented Nov 7, 2022

@imsodin Any chance we can get this into the upcoming release?

@imsodin
Copy link
Member Author

imsodin commented Nov 7, 2022

Added a heuristic for the schema migration to detect affected files. Please re-review those bits.

* main: (36 commits)
  lib/protocol: Ignore inode time when xattr&ownership is ignored (fixes syncthing#8654) (syncthing#8655)
  lib/fs: Try to remove read only Windows files (fixes syncthing#3744) (syncthing#8650)
  gui: Add copy to clipboard, share by email, and share by SMS buttons to device IDs (fixes syncthing#2771, ref syncthing#3868) (syncthing#7984)
  gui, man, authors: Update docs, translations, and contributors
  build: Add GitHub actions build for Windows (syncthing#8627)
  gui: Fix connection type icon width (fixes syncthing#8592) (syncthing#8644)
  gui: Adjust connection type icon size scaling and alignment (syncthing#8645)
  docker: Use healthcheck endpoint (syncthing#8640)
  lib/connections: Use adaptive write size for rate limited connections (fixes syncthing#8630) (syncthing#8631)
  gui: Mark devices that haven't connected for a long time (fixes syncthing#7703) (syncthing#8530)
  gui: Fix rescan interval when add encrypted folder with watch for changes enabled (fixes syncthing#8570) (syncthing#8571)
  gui: Always show Out of Sync Items for remote devices (syncthing#8632)
  lib/fs: Let xattr test avoid non-test attributes (fixes syncthing#8601) (syncthing#8628)
  build: Add GitHub actions build for Windows
  gui, man, authors: Update docs, translations, and contributors
  gui: Display folder and device count number (syncthing#8615)
  gui, man, authors: Update docs, translations, and contributors
  lib/model, lib/protocol: Fix file comparisons (fixes syncthing#8594) (syncthing#8603)
  lib/scanner: More sensible debug output (syncthing#8596)
  gui: Allow automatic device ID selection on WebKit browsers (ref syncthing#8544) (syncthing#8597)
  ...
Copy link
Member

@calmh calmh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some points of confusion, I'll hack it a little and see if I can make it work.

@calmh
Copy link
Member

calmh commented Nov 8, 2022

So, again, It's Not That Easy(tm). The scanner is fine now I think, that part works for me, though it is a bit slower than before because we actually need to open the file and read a few bytes to figure out it's pre-trailer size. Another option here might be to just not do that and instead ignore size when looking at receive-encrypted files...

The migration is trickier because we don't easily have the size to subtract. It's not the protocol.EncryptedTrailerSize of the FileInfo we're looking at, because we're not looking at the FileInfo we got from the remote device but the one we stored locally. It's different in that we've changed the sequence, added an inode change time (yeah sorry) and maybe other things (mtimefs?) so the size when encoded doesn't correspond to the original. We could maybe try to find the original in the database, but we could have multiple peers and it's not guaranteed which one we were looking at at the time and they're not guaranteed to be identical (just equivalent).

I'm tempted to skip the migration and let revert-local-changes sort it out, either by triggering that automatically on upgrade or just noting that it needs to happen to clear out the state...

@acolomb
Copy link
Member

acolomb commented Nov 8, 2022

Just a quick thought without having looked at the details... Could we add some kind of version field to the trailer? If it doesn't match what we use (from now on), the info is nuked and recalculated? Kind of an on-the-fly migration.

@imsodin
Copy link
Member Author

imsodin commented Nov 8, 2022

We should probably only write FileInfo.Encrypted to the trailer - I don't think we need any of the synthetic info in the main file to decrypt? Then we know the trailer size exactly and don't need to read the data on scan. Where's the "It's Not That Easy(tm)" here - pretty sure it is there?

The in the migration we'd need to be even smarter, rewriting the files and such. Really tempted to just drop it all and redo then, but in this case I do think we should combine it with #7987 and shortening the path segments - meaning delay the fix. Sure it's labeled beta, but doing a full drop twice seems quite mean.

@calmh
Copy link
Member

calmh commented Nov 8, 2022

Well, the "it's not that easy" referred to the current state where it's quite difficult to do the migration.

But it's also not that easy that we can just write the encrypted part, though it would have been convenient, because the key to the encryption of that bundle and the file itself is based on the file name, which we get from decrypting the name in the "outer" fileinfo using the folder key...

We could add a local attribute to the fileinfo to store the file-on-disk-with-trailer for comparison purposes, or we could just not try to detect random size changes to encrypted files in the scanner...

@imsodin
Copy link
Member Author

imsodin commented Dec 21, 2022

Ok, next try.

Motivation: I don't want to open files while scanning, and I still want to detect changed files. Also have a transition such that the existing setup stays usable, because it was simple-ish to do with the solution I came up with for the previous motivations. And fixing the bug of course.

Approach: Add a new field to the file-info, for the trailer size. Then still add the trailer size to the file-size to get an accurate total local size of a folder. Use the trailer size field in the index sender to send the correct (no trailer) size to remotes (fixes this bug).
I also added a new type of "global migration" in lib/syncthing which populates that field for existing files. I didn't do it in a db migration, as it feels wrong to do filesystem stuff there. Even more so with my current plan for #7987, where I'll actually have to move/rename files in the transition. If you feel this one should be a plain db transition, I could pass some EncryptionTrailerTransitionHelper interface to the db migration with methods to check if a folder is recv-enc and returning the trailer size for a filename.

I tested it locally and no local changes happened on the transition.

calmh added 3 commits March 10, 2023 12:27
* main: (46 commits)
  build: Update dependencies
  lib/api: Expose `blocksHash` in file info (syncthing#8810)
  gui, man, authors: Update docs, translations, and contributors
  lib/discover: Don't leak relay-tokens to discovery (syncthing#8762)
  gui, man, authors: Update docs, translations, and contributors
  gui: Add Croatian (hr) translation template (syncthing#8801)
  build(deps): bump github.com/quic-go/quic-go from 0.32.0 to 0.33.0 (syncthing#8800)
  cmd/stupgrades: Cache should apply to HEAD as well as GET
  build: Add more GitHub Actions
  gui: Remove non-existent customicons.css file reference (fixes syncthing#8797) (syncthing#8798)
  Only fail after chmod error if permissions differ (e.g. on config file) (syncthing#8771)
  gui, man, authors: Update docs, translations, and contributors
  build: Use Go 1.19.6 for Windows
  build: Update dependencies
  gui, man, authors: Update docs, translations, and contributors
  gui: Remove duplicate Spanish (Spain) translation (fixes syncthing#8781) (syncthing#8782)
  gui: Add xattr filter editor (fixes syncthing#8660) (syncthing#8734)
  gui: Switch to Weblate for translations (syncthing#8777)
  all: Use new Go 1.19 atomic types (syncthing#8772)
  gui, man, authors: Update docs, translations, and contributors
  ...
* main:
  gui: Disable Restore Versions filters when no versioned files exist (fixes syncthing#5408) (syncthing#8539)
  build(deps): bump github.com/chmduquesne/rollinghash from 0.0.0-20180912150627-a60f8e7142b5 to 4.0.0+incompatible (syncthing#8804)
  build: Update dependencies (syncthing#8821)
@calmh calmh merged commit da72df6 into syncthing:main Mar 10, 2023
calmh added a commit to calmh/syncthing that referenced this pull request Mar 10, 2023
* main:
  gui: Add Persian (fa) translation template (syncthing#8822)
  lib: Correctly handle encrypted trailer size (fixes syncthing#8556) (syncthing#8563)
  gui: Disable Restore Versions filters when no versioned files exist (fixes syncthing#5408) (syncthing#8539)
  build(deps): bump github.com/chmduquesne/rollinghash from 0.0.0-20180912150627-a60f8e7142b5 to 4.0.0+incompatible (syncthing#8804)
  build: Update dependencies (syncthing#8821)
calmh added a commit to calmh/syncthing that referenced this pull request Mar 10, 2023
* main:
  gui: Add Persian (fa) translation template (syncthing#8822)
  lib: Correctly handle encrypted trailer size (fixes syncthing#8556) (syncthing#8563)
  gui: Disable Restore Versions filters when no versioned files exist (fixes syncthing#5408) (syncthing#8539)
  build(deps): bump github.com/chmduquesne/rollinghash from 0.0.0-20180912150627-a60f8e7142b5 to 4.0.0+incompatible (syncthing#8804)
  build: Update dependencies (syncthing#8821)
@imsodin imsodin deleted the fix-8556 branch March 10, 2023 17:04
calmh added a commit to calmh/syncthing that referenced this pull request Mar 12, 2023
* main:
  lib/protocol: Cache expensive key operations (fixes syncthing#8599) (syncthing#8820)
  gui: Add Persian (fa) translation template (syncthing#8822)
  lib: Correctly handle encrypted trailer size (fixes syncthing#8556) (syncthing#8563)
  gui: Disable Restore Versions filters when no versioned files exist (fixes syncthing#5408) (syncthing#8539)
  build(deps): bump github.com/chmduquesne/rollinghash from 0.0.0-20180912150627-a60f8e7142b5 to 4.0.0+incompatible (syncthing#8804)
  build: Update dependencies (syncthing#8821)
@calmh calmh added this to the v1.23.3 milestone Mar 14, 2023
calmh added a commit to tomasz1986/syncthing that referenced this pull request Mar 18, 2023
* main: (424 commits)
  gui, man, authors: Update docs, translations, and contributors
  lib/protocol: Cache expensive key operations (fixes syncthing#8599) (syncthing#8820)
  gui: Add Persian (fa) translation template (syncthing#8822)
  lib: Correctly handle encrypted trailer size (fixes syncthing#8556) (syncthing#8563)
  gui: Disable Restore Versions filters when no versioned files exist (fixes syncthing#5408) (syncthing#8539)
  build(deps): bump github.com/chmduquesne/rollinghash from 0.0.0-20180912150627-a60f8e7142b5 to 4.0.0+incompatible (syncthing#8804)
  build: Update dependencies (syncthing#8821)
  lib/api: Expose `blocksHash` in file info (syncthing#8810)
  gui, man, authors: Update docs, translations, and contributors
  lib/discover: Don't leak relay-tokens to discovery (syncthing#8762)
  gui, man, authors: Update docs, translations, and contributors
  gui: Add Croatian (hr) translation template (syncthing#8801)
  build(deps): bump github.com/quic-go/quic-go from 0.32.0 to 0.33.0 (syncthing#8800)
  cmd/stupgrades: Cache should apply to HEAD as well as GET
  build: Add more GitHub Actions
  gui: Remove non-existent customicons.css file reference (fixes syncthing#8797) (syncthing#8798)
  Only fail after chmod error if permissions differ (e.g. on config file) (syncthing#8771)
  gui, man, authors: Update docs, translations, and contributors
  build: Use Go 1.19.6 for Windows
  build: Update dependencies
  ...
imsodin added a commit to imsodin/syncthing that referenced this pull request Mar 28, 2023
…ng#8556)

In the original fix in syncthing#8563 I simply forgot this. Which meant syncthing#8556
wasn't actually fixed, as the trialer size would have been 0 (default),
and thus we would have still sent the inflated size to encrypted peers.
imsodin added a commit to imsodin/syncthing that referenced this pull request Mar 28, 2023
Fixes a regression due to PR syncthing#8563, while arguable the bug was actually
introduced in a much older PR syncthing#7155, but didn't have any bad effects so
far:
We account for the encryption trailer in the db updater routine,
calculating the file-info size there. However there's no guarantee that
the file-info at this point is still the exact same as when it was
written. It was before, but isn't anymore since introducing the new
EncryptedTrailerSize field.
Fix: Adjust the size in the info at the same place where the trailer is
written, i.e. we definitely have the actual size on disk.
calmh pushed a commit that referenced this pull request Mar 28, 2023
lib/model: Fix file size inconsisency due to enc. trailer

Fixes a regression due to PR #8563, while arguable the bug was actually
introduced in a much older PR #7155, but didn't have any bad effects so
far:
We account for the encryption trailer in the db updater routine,
calculating the file-info size there. However there's no guarantee that
the file-info at this point is still the exact same as when it was
written. It was before, but isn't anymore since introducing the new
EncryptedTrailerSize field.
Fix: Adjust the size in the info at the same place where the trailer is
written, i.e. we definitely have the actual size on disk.
imsodin added a commit to imsodin/syncthing that referenced this pull request Mar 28, 2023
…ng#8556)

In the original fix in syncthing#8563 I simply forgot this. Which meant syncthing#8556
wasn't actually fixed, as the trialer size would have been 0 (default),
and thus we would have still sent the inflated size to encrypted peers.
calmh pushed a commit that referenced this pull request Mar 28, 2023
In the original fix in #8563 I simply forgot this. Which meant #8556
wasn't actually fixed, as the trialer size would have been 0 (default),
and thus we would have still sent the inflated size to encrypted peers.
calmh added a commit to calmh/syncthing that referenced this pull request Apr 14, 2023
* main: (28 commits)
  build: Update dependencies (syncthing#8869)
  lib/model: Improve path generation for auto accepted folders (fixes syncthing#8859) (syncthing#8860)
  docs: fix typo (syncthing#8857)
  gui, man, authors: Update docs, translations, and contributors
  lib/syncthing: Handle successful global migration (fixes syncthing#8851) (syncthing#8852)
  gui, man, authors: Update docs, translations, and contributors
  lib/model: Set enc. trailer size on pull (ref syncthing#8563, syncthing#8556) (syncthing#8839)
  lib/model: Fix file size inconsistency due to enc. trailer (syncthing#8840)
  gui, man, authors: Update docs, translations, and contributors
  cmd/stdiscorv: Fix database test (fixes syncthing#8828)
  lib/ur: Fix custom releases URL comparison
  gui: Remove untranslated strings from JSON files (syncthing#8836)
  all: Fix typos found by codespell (syncthing#8833)
  gui: Hide download progress legend when download progress is disabled
  gui, man, authors: Update docs, translations, and contributors
  lib/protocol: Handle encrypted requests without encrypted hash (fixes syncthing#8277) (syncthing#8827)
  build(deps): bump github.com/hashicorp/golang-lru/v2 from 2.0.1 to 2.0.2 (syncthing#8826)
  lib/config: Allow sub-second watcher delay (fixes syncthing#7859) (syncthing#7864)
  gui, man, authors: Update docs, translations, and contributors
  lib/protocol: Cache expensive key operations (fixes syncthing#8599) (syncthing#8820)
  ...
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Mar 9, 2024
@syncthing syncthing locked and limited conversation to collaborators Mar 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Increased file size when sharing between encrypted devices

4 participants