diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b594f7835..7368424dfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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\] diff --git a/internal/pkg/util/fs/helper.go b/internal/pkg/util/fs/helper.go index 3abdf731b7..ace0be0897 100644 --- a/internal/pkg/util/fs/helper.go +++ b/internal/pkg/util/fs/helper.go @@ -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. @@ -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 diff --git a/pkg/image/image.go b/pkg/image/image.go index f14946e5f6..93061be33e 100644 --- a/pkg/image/image.go +++ b/pkg/image/image.go @@ -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. @@ -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),