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

text attributes: validate more strictly, fixes #2290 #7197

Merged
merged 7 commits into from
Dec 15, 2022

Conversation

ThomasWaldmann
Copy link
Member

@ThomasWaldmann ThomasWaldmann commented Dec 10, 2022

  • archive names
  • archive comments

also: kill the b* (bpath, barchive, bcomment) stuff.

  • barchive and bcomment is not needed any more (validated plain text, nothing binary / strange inside)
  • bpath will need to get solved otherwise later, maybe as base64-* element (for json, which allows only pure text)

@ThomasWaldmann ThomasWaldmann force-pushed the valid-archive-names branch 2 times, most recently from 901a82e to e2be00d Compare December 10, 2022 19:16
@codecov-commenter
Copy link

codecov-commenter commented Dec 10, 2022

Codecov Report

Merging #7197 (b9dc2be) into master (de6d8af) will decrease coverage by 0.02%.
The diff coverage is 77.41%.

@@            Coverage Diff             @@
##           master    #7197      +/-   ##
==========================================
- Coverage   83.52%   83.50%   -0.03%     
==========================================
  Files          67       67              
  Lines       11486    11540      +54     
  Branches     2078     2090      +12     
==========================================
+ Hits         9594     9636      +42     
- Misses       1343     1354      +11     
- Partials      549      550       +1     
Impacted Files Coverage Δ
src/borg/archiver/list_cmd.py 100.00% <ø> (ø)
src/borg/archiver/rlist_cmd.py 100.00% <ø> (ø)
src/borg/archiver/transfer_cmd.py 73.63% <44.00%> (-8.93%) ⬇️
src/borg/archiver/create_cmd.py 78.77% <100.00%> (ø)
src/borg/archiver/recreate_cmd.py 96.36% <100.00%> (ø)
src/borg/archiver/tar_cmds.py 84.16% <100.00%> (ø)
src/borg/helpers/__init__.py 100.00% <100.00%> (ø)
src/borg/helpers/parseformat.py 89.39% <100.00%> (+0.84%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

we want to be able to use an archive name as a directory name,
e.g. for the FUSE fs built by borg mount.

thus we can not allow "/" in an archive name on linux.

on windows, the rules are more restrictive, disallowing
quite some more characters (':<>"|*?' plus some more).
we do not have FUSE fs / borg mount on windows yet, but
we better avoid any issues.
we can not avoid ":" though, as our {now} placeholder
generates ISO-8601 timestamps, including ":" chars.

also, we do not want to have leading/trailing blanks in
archive names, neither surrogate-escapes.

control chars are disallowed also, including chr(0).
we have python str here, thus chr(0) is not expected in there
(is not used to terminate a string, like it is in C).
Comment on lines +546 to +551
MAX_PATH = 260 # Windows default. Since Win10, there is a registry setting LongPathsEnabled to get more.
MAX_DIRNAME = MAX_PATH - len("12345678.123")
SAFETY_MARGIN = 48 # borgfs path: mountpoint / archivename / dir / dir / ... / file
MAX_ARCHIVENAME = MAX_DIRNAME - SAFETY_MARGIN
if not (0 < len(text) <= MAX_ARCHIVENAME):
raise argparse.ArgumentTypeError(f'Invalid archive name: "{text}" [0 < length <= {MAX_ARCHIVENAME}]')
Copy link
Member Author

Choose a reason for hiding this comment

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

Since we can not rely on LongPathsEnabled and we also need some (48) chars for the mountpoint and path components inside the archivename directory, we are now down to 200 chars max for the archivename.

not needed any more as the comment is now validated pure text.
not needed any more as the archive name is now validated pure text.
this needs to get done differently later, maybe base64 for json output.
@ThomasWaldmann ThomasWaldmann changed the title archive names: validate more strictly, fixes #2290 text attributes: validate more strictly, fixes #2290 Dec 12, 2022
@ThomasWaldmann ThomasWaldmann merged commit d0d21e7 into borgbackup:master Dec 15, 2022
@ThomasWaldmann ThomasWaldmann deleted the valid-archive-names branch December 15, 2022 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants