Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Bug Fixes

- Correctly launch CleanupHost process only when needed in `--sif-fuse` flow.
- Add specific error for unreadable image / overlay file.

## 3.10.0-rc.1 \[2022-05-04\]

Expand Down
10 changes: 8 additions & 2 deletions internal/pkg/util/fs/helper.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2021, Sylabs Inc. All rights reserved.
// Copyright (c) 2018-2022, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand Down Expand Up @@ -397,7 +397,13 @@ func CopyFileAtomic(from, to string, mode os.FileMode) (err error) {
return nil
}

// IsWritable returns true of the file that is passed in
// IsReadable returns true if the file that is passed in
// is readable by the user (note: uid is checked, not euid).
func IsReadable(path string) bool {
return unix.Access(path, unix.R_OK) == nil
}

// IsWritable returns true if the file that is passed in
// is writable by the user (note: uid is checked, not euid).
func IsWritable(path string) bool {
return unix.Access(path, unix.W_OK) == nil
Expand Down
6 changes: 5 additions & 1 deletion pkg/image/image.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2020, Sylabs Inc. All rights reserved.
// Copyright (c) 2018-2022, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand Down Expand Up @@ -393,6 +393,10 @@ func Init(path string, writable bool) (*Image, error) {
return nil, err
}

if !fs.IsReadable(resolvedPath) {
return nil, fmt.Errorf("%s is not readable by the current user, check permissions", resolvedPath)
}

img := &Image{
Path: resolvedPath,
Name: filepath.Base(resolvedPath),
Expand Down