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 crash when the file name being statted is just "\n" #2933

Merged
merged 4 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 11 additions & 3 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,9 @@ func (fs *fileSystem) lookUpOrCreateChildInode(
parent inode.DirInode,
childName string) (child inode.Inode, err error) {
// First check if the requested child is a localFileInode.
child = fs.lookUpLocalFileInode(parent, childName)
if child, err = fs.lookUpLocalFileInode(parent, childName); err != nil {
return child, err
kislaykishore marked this conversation as resolved.
Show resolved Hide resolved
}
if child != nil {
vadlakondaswetha marked this conversation as resolved.
Show resolved Hide resolved
return
}
Expand Down Expand Up @@ -1036,8 +1038,11 @@ func (fs *fileSystem) lookUpOrCreateChildInode(
// LOCKS_EXCLUDED(parent)
// UNLOCK_FUNCTION(fs.mu)
// LOCK_FUNCTION(child)
func (fs *fileSystem) lookUpLocalFileInode(parent inode.DirInode, childName string) (child inode.Inode) {
func (fs *fileSystem) lookUpLocalFileInode(parent inode.DirInode, childName string) (child inode.Inode, err error) {
// Trim the suffix assigned to fix conflicting names.
if childName == inode.ConflictingFileNameSuffix {
return child, syscall.ENOENT
kislaykishore marked this conversation as resolved.
Show resolved Hide resolved
}
childName = strings.TrimSuffix(childName, inode.ConflictingFileNameSuffix)
fileName := inode.NewFileName(parent.Name(), childName)

Expand Down Expand Up @@ -2009,7 +2014,10 @@ func (fs *fileSystem) Rename(
}

// If object to be renamed is a local file inode (un-synced), rename operation is not supported.
localChild := fs.lookUpLocalFileInode(oldParent, op.OldName)
localChild, err := fs.lookUpLocalFileInode(oldParent, op.OldName)
if err != nil {
return err
}
if localChild != nil {
fs.unlockAndDecrementLookupCount(localChild, 1)
return fmt.Errorf("cannot rename open file %q: %w", op.OldName, syscall.ENOTSUP)
Expand Down
34 changes: 34 additions & 0 deletions tools/integration_tests/operations/stat_file_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package operations_test

import (
"os"
"syscall"
"testing"

"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/setup"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestStatWithTrailingNewline(t *testing.T) {
testDir := setup.SetupTestDirectory(DirForOperationTests)

_, err := os.Stat(testDir + "/\n")

require.Error(t, err)
assert.Equal(t, err.(*os.PathError).Err, syscall.ENOENT)
}
Loading