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

jgit considers the file path src/Con.java invalid on Windows #129

Open
Luro02 opened this issue Jan 11, 2025 · 3 comments
Open

jgit considers the file path src/Con.java invalid on Windows #129

Luro02 opened this issue Jan 11, 2025 · 3 comments

Comments

@Luro02
Copy link

Luro02 commented Jan 11, 2025

Version

7.1.0.202411261347-r

Operating System

Windows

Bug description

On Windows certain filenames are forbidden like CON.
jgit validates the file paths and throws an exception if it is not valid.

In my case the filepath is src/Con.java, where Con.java is a file and src is a folder.

The validation code does not seem to consider the file extension.

The filename Con.java is a valid file on windows:
image
CON (without any extension) is considered invalid:
image

Actual behavior

org.eclipse.jgit.dircache.InvalidPathException: Invalid path: src/Con.java
	at org.eclipse.jgit.dircache.DirCacheCheckout.checkValidPathSegment(DirCacheCheckout.java:1609)
	at org.eclipse.jgit.dircache.DirCacheCheckout.checkValidPath(DirCacheCheckout.java:1598)
	at org.eclipse.jgit.dircache.DirCacheCheckout.processEntry(DirCacheCheckout.java:387)
	at org.eclipse.jgit.dircache.DirCacheCheckout.prescanOneTree(DirCacheCheckout.java:354)
	at org.eclipse.jgit.dircache.DirCacheCheckout.doCheckout(DirCacheCheckout.java:512)
	at org.eclipse.jgit.dircache.DirCacheCheckout.checkout(DirCacheCheckout.java:480)
        ...
Caused by: org.eclipse.jgit.errors.CorruptObjectException: invalid name 'CON'
	at org.eclipse.jgit.lib.ObjectChecker.report(ObjectChecker.java:781)
	at org.eclipse.jgit.lib.ObjectChecker.checkNotWindowsDevice(ObjectChecker.java:1029)
	at org.eclipse.jgit.lib.ObjectChecker.checkPathSegment2(ObjectChecker.java:903)
	at org.eclipse.jgit.lib.ObjectChecker.checkPathSegment(ObjectChecker.java:849)
	at org.eclipse.jgit.dircache.DirCacheCheckout.checkValidPathSegment(DirCacheCheckout.java:1606)
	... 45 more

Expected behavior

No crash

Relevant log output

No response

Other information

No response

@tomaswolf
Copy link
Contributor

Interesting. According to the commit message of the commit that introduced this check this is intentional. Beats me why, though.

@Luro02
Copy link
Author

Luro02 commented Jan 11, 2025

Interesting. According to the commit message of the commit that introduced this check this is intentional. Beats me why, though.

image

Not sure why one would want to prevent cloning of these files, they are perfectly valid.

An option to disable these checks would have been nice... Overriding the SystemReader to return false for windows is technically an option, but it does not work because then the code will try to set posix properties on the file...

@msohn
Copy link
Member

msohn commented Jan 12, 2025

Microsoft recommends to not use such names, see https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file which says

Do not use the following reserved names for the name of a file:

CON, PRN, AUX, NUL, COM0, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, COM¹, COM², COM³, LPT0, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9, LPT¹, LPT², and LPT³. Also avoid these names followed immediately by an extension; for example, NUL.txt and NUL.tar.gz are both equivalent to NUL. For more information, see Namespaces.

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

No branches or pull requests

3 participants