-
Notifications
You must be signed in to change notification settings - Fork 284
Fix macos filename encoding #949
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
Open
rafjaf
wants to merge
4
commits into
rfjakob:master
Choose a base branch
from
rafjaf:rebase-onto-2.6.0
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
58f1ec0
macOS: Fix Unicode normalization issues in forward & reverse mode
rafjaf 5b82f42
Added testing for forward mode, and reverted all changes for reverse …
rafjaf c72b8d2
Reverting node_dir_ops in reverse mode to initial version
rafjaf 007129c
Created additional tests for macos filename encoding normalization fix
rafjaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,7 +1,11 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
package fusefrontend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"runtime" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"syscall" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"unicode/utf8" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"golang.org/x/text/unicode/norm" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"github.com/rfjakob/gocryptfs/v2/internal/tlog" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -10,12 +14,10 @@ import ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"github.com/rfjakob/gocryptfs/v2/internal/syscallcompat" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// prepareAtSyscall returns a (dirfd, cName) pair that can be used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// with the "___at" family of system calls (openat, fstatat, unlinkat...) to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// access the backing encrypted child file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func (n *Node) prepareAtSyscall(child string) (dirfd int, cName string, errno syscall.Errno) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// prepareAtSyscallDirect is the direct version without Unicode normalization fallback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func (n *Node) prepareAtSyscallDirect(child string) (dirfd int, cName string, errno syscall.Errno) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if child == "" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tlog.Warn.Printf("BUG: prepareAtSyscall: child=%q, should have called prepareAtSyscallMyself", child) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tlog.Warn.Printf("BUG: prepareAtSyscallDirect: child=%q, should have called prepareAtSyscallMyself", child) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return n.prepareAtSyscallMyself() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -92,6 +94,48 @@ func (n *Node) prepareAtSyscall(child string) (dirfd int, cName string, errno sy | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// prepareAtSyscall returns a (dirfd, cName) pair that can be used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// with the "___at" family of system calls (openat, fstatat, unlinkat...) to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// access the backing encrypted child file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func (n *Node) prepareAtSyscall(child string) (dirfd int, cName string, errno syscall.Errno) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if child == "" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tlog.Warn.Printf("BUG: prepareAtSyscall: child=%q, should have called prepareAtSyscallMyself", child) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return n.prepareAtSyscallMyself() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// On macOS, implement Unicode normalization with fallback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if runtime.GOOS == "darwin" && utf8.ValidString(child) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Step 1: Always try NFC first (canonical storage form) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
normalizedChild := norm.NFC.String(child) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dirfd, cName, errno = n.prepareAtSyscallDirect(normalizedChild) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if errno == 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return dirfd, cName, 0 // Found NFC version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Step 2: Try alternate form if input was different | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if normalizedChild != child { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Input was NFD, try original NFD form | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dirfdNFD, cNameNFD, errnoNFD := n.prepareAtSyscallDirect(child) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if errnoNFD == 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return dirfdNFD, cNameNFD, 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Step 3: If input was NFC, also try NFD as fallback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if normalizedChild == child { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
nfdChild := norm.NFD.String(child) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if nfdChild != child { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dirfdNFD, cNameNFD, errnoNFD := n.prepareAtSyscallDirect(nfdChild) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if errnoNFD == 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return dirfdNFD, cNameNFD, 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return n.prepareAtSyscallDirect(child) // Non-macOS or fallback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The logic for trying different normalization forms is complex and could be simplified. Consider extracting the normalization attempts into a separate helper function to improve readability and maintainability.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func (n *Node) prepareAtSyscallMyself() (dirfd int, cName string, errno syscall.Errno) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dirfd = -1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition checks if input was NFC after already trying NFC and NFD. This creates redundant NFD normalization when the input was already NFC. Consider restructuring to avoid duplicate normalization calls.
Copilot uses AI. Check for mistakes.