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

Fix parseInfoFile does not handle spaces in filenames #3159

Merged
merged 2 commits into from
Apr 2, 2019

Conversation

thaJeztah
Copy link
Member

equivalent to moby/moby#38977, for containerd

relates to moby/moby#38458
relates to kubernetes/kubernetes#35062

/proc/self/mountinfo uses \040 for spaces, however, parseInfoFile()
did not decode those spaces in paths, therefore attempting to use \040
as a literal part of the path.

This patch un-quotes the root and mount point fields to fix
situations where paths contain spaces.

Note that the mount source field is not modified, given that
this field is documented (man PROC(5)) as:

filesystem-specific information or "none"

Which I interpreted as "the format in this field is undefined".

Thanks to @remexre for reporting, and @itizir, @sergei-utinski for suggesting the patch.

@thaJeztah
Copy link
Member Author

ping @kolyshkin PTAL

Optional: "",
FSType: "cifs",
Source: `//foo/BLA\040BLA\040BLA/`,
VFSOptions: `rw,sec=ntlm,cache=loose,unc=\\foo\BLA`,
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that this is truncating all options after the space; this is documented in parseInfoFile as expected, but I'm thinking of doing a follow-up to preserve the information that was removed (this might need some discussion, so I'm keeping that separate)

@@ -21,6 +21,7 @@ package mount
import (
"bufio"
"fmt"
"github.com/pkg/errors"
Copy link
Member

Choose a reason for hiding this comment

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

could we move it to next package group?

Copy link
Member Author

Choose a reason for hiding this comment

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

oh! yes, looks like my editor inserted it

}

if len(infos) != len(expected) {
t.Fatalf("Expected %d entries, got %d", len(expected), len(infos))
Copy link
Member

Choose a reason for hiding this comment

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

s/Expected/expected use lowercase here

@fuweid
Copy link
Member

fuweid commented Apr 2, 2019

I think we should use one commit here :)

`/proc/self/mountinfo` uses `\040` for spaces, however, `parseInfoFile()`
did not decode those spaces in paths, therefore attempting to use `\040`
as a literal part of the path.

This patch un-quotes the `root` and `mount point` fields to fix
situations where paths contain spaces.

Note that the `mount source` field is not modified, given that
this field is documented (man `PROC(5)`) as:

    filesystem-specific information or "none"

Which I interpreted as "the format in this field is undefined".

Reported-by: Daniil Yaroslavtsev <daniilyar@users.noreply.github.com>
Reported-by: Nathan Ringo <remexre@gmail.com>
Based-on-patch-by: Diego Becciolini <itizir@users.noreply.github.com>
Based-on-patch-by: Sergei Utinski <sergei-utinski@users.noreply.github.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
Copy link
Member Author

updated 👍

I think we should use one commit here :)

I kept the pkg/errors change separate as it was not directly related to the fix (and in case cherry-picking to release-branches would be more complicated because of those), but happy to squash if the maintainers prefer

@fuweid
Copy link
Member

fuweid commented Apr 2, 2019

flaky case show up again 🤷‍♂️

@thaJeztah could you mind to repush again? thanks

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
Copy link
Member Author

pushed again 👍

@codecov-io
Copy link

codecov-io commented Apr 2, 2019

Codecov Report

Merging #3159 into master will decrease coverage by 3.08%.
The diff coverage is 25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3159      +/-   ##
==========================================
- Coverage   45.46%   42.38%   -3.09%     
==========================================
  Files         104      115      +11     
  Lines       10198    12751    +2553     
==========================================
+ Hits         4637     5404     +767     
- Misses       4738     6513    +1775     
- Partials      823      834      +11
Flag Coverage Δ
#linux 45.45% <25%> (-0.02%) ⬇️
#windows 40.47% <ø> (?)
Impacted Files Coverage Δ
mount/mountinfo_linux.go 57.4% <25%> (-3.82%) ⬇️
snapshots/native/native.go 43.04% <0%> (-9.99%) ⬇️
metadata/snapshot.go 45.8% <0%> (-8.96%) ⬇️
archive/tar.go 43.79% <0%> (-7.07%) ⬇️
metadata/containers.go 47.97% <0%> (-6.62%) ⬇️
content/local/writer.go 57.84% <0%> (-6.36%) ⬇️
content/local/store.go 48.51% <0%> (-5.03%) ⬇️
metadata/images.go 57.57% <0%> (-4.99%) ⬇️
archive/tar_opts.go 28.57% <0%> (-4.77%) ⬇️
archive/compression/compression.go 58.69% <0%> (-4.7%) ⬇️
... and 62 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bc8a189...adc4fa2. Read the comment docs.

1 similar comment
@codecov-io
Copy link

Codecov Report

Merging #3159 into master will decrease coverage by 3.08%.
The diff coverage is 25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3159      +/-   ##
==========================================
- Coverage   45.46%   42.38%   -3.09%     
==========================================
  Files         104      115      +11     
  Lines       10198    12751    +2553     
==========================================
+ Hits         4637     5404     +767     
- Misses       4738     6513    +1775     
- Partials      823      834      +11
Flag Coverage Δ
#linux 45.45% <25%> (-0.02%) ⬇️
#windows 40.47% <ø> (?)
Impacted Files Coverage Δ
mount/mountinfo_linux.go 57.4% <25%> (-3.82%) ⬇️
snapshots/native/native.go 43.04% <0%> (-9.99%) ⬇️
metadata/snapshot.go 45.8% <0%> (-8.96%) ⬇️
archive/tar.go 43.79% <0%> (-7.07%) ⬇️
metadata/containers.go 47.97% <0%> (-6.62%) ⬇️
content/local/writer.go 57.84% <0%> (-6.36%) ⬇️
content/local/store.go 48.51% <0%> (-5.03%) ⬇️
metadata/images.go 57.57% <0%> (-4.99%) ⬇️
archive/tar_opts.go 28.57% <0%> (-4.77%) ⬇️
archive/compression/compression.go 58.69% <0%> (-4.7%) ⬇️
... and 62 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bc8a189...adc4fa2. Read the comment docs.

Copy link
Member

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

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

LGTM

@estesp estesp merged commit 22bb5eb into containerd:master Apr 2, 2019
@thaJeztah thaJeztah deleted the fix_parseinfofile_parsing branch April 2, 2019 13:42
kolyshkin added a commit to kolyshkin/sys that referenced this pull request Jun 23, 2020
Moby PR #38977 [1] and containerd PR #3159 [2] added the handing of
escape sequences in mountinfo paths (root and mountpoint fields).

Unfortunately, it also broke the handling of paths containing double
quotes, as it was pointed out in [3].

The solution is to stop using strconv.Unquote and write our own
specialized function to deal with escape sequences.

Unit tests added.

[1] moby/moby#38977
[2] containerd/containerd#3159
[3] containerd/containerd#4257

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin added a commit to kolyshkin/sys that referenced this pull request Jun 23, 2020
Moby PR #38977 [1] and containerd PR #3159 [2] added the handing of
escape sequences in mountinfo paths (root and mountpoint fields).

Unfortunately, it also broke the handling of paths containing double
quotes, as it was pointed out in [3].

The solution is to stop using strconv.Unquote and write our own
specialized function to deal with escape sequences.

Unit tests added.

[1] moby/moby#38977
[2] containerd/containerd#3159
[3] containerd/containerd#4257

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin added a commit to kolyshkin/sys that referenced this pull request Jun 23, 2020
Moby PR #38977 [1] and containerd PR #3159 [2] added the handing of
escape sequences in mountinfo paths (root and mountpoint fields).

Unfortunately, it also broke the handling of paths containing double
quotes, as it was pointed out in [3].

The solution is to stop using strconv.Unquote and write our own
specialized function to deal with escape sequences.

Unit tests added.

[1] moby/moby#38977
[2] containerd/containerd#3159
[3] containerd/containerd#4257

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
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.

None yet

4 participants