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

git_repository_init_ext and git_clone fail with path too long #6604

Open
pde-cds opened this issue Jul 20, 2023 · 6 comments
Open

git_repository_init_ext and git_clone fail with path too long #6604

pde-cds opened this issue Jul 20, 2023 · 6 comments

Comments

@pde-cds
Copy link

pde-cds commented Jul 20, 2023

Regarding libgit2/libgit2sharp#2051

Reproduction steps

When using git_repository_init_ext and git_clone on a path which is longer than 260, it will fail with path too long

Expected behavior

work like expected

Actual behavior

path too long

Version of libgit2 (release number or SHA1)

1.6.4 through LibGit2Sharp.NativeBinaries 2.0.320

Operating system(s) tested

Win 10 22H2

@ethomson
Copy link
Member

Is this a libgit2 problem or a LibGit2Sharp problem? If it's the former, can you provide repro steps?

@pde-cds
Copy link
Author

pde-cds commented Jul 20, 2023

I can reproduce it through LibGit2Sharp, but the error comes from libgit2.
Because of this, I created this issue additionally to the one in libgit2sharp

@ethomson
Copy link
Member

Did you read this documentation?

======================

@pde-cds
Copy link
Author

pde-cds commented Jul 20, 2023

Well thats nice to now. As coming from LibGit2Sharp there was no such information
Never the less we used a modified version of 0.26.2 with usage of libgit2 with ianhattendorf's changes (#5347) and preset of GIT_OPT_SET_WINDOWS_LONGPATHS with this version there were no problems with an git repo in a path longer than 260.
So the behaviour of this has changed since.
Regarding the Windows 260 char problems: Shouldn't be handled by the OS/filesystem if those path cannot be worked with?
Is there a need to restrict the path inside of libgit2?

@pde-cds
Copy link
Author

pde-cds commented Jul 24, 2023

After testing some changes in libgit2, I found our problem which seems to be util/fs_path.c/git_fs_path_validate_str_length_with_suffix

libgit2/src/util/fs_path.c

Lines 1727 to 1748 in 42b5d85

int git_fs_path_validate_str_length_with_suffix(
git_str *path,
size_t suffix_len)
{
#ifdef GIT_WIN32
size_t utf8_len = git_utf8_char_length(path->ptr, path->size);
size_t total_len;
if (GIT_ADD_SIZET_OVERFLOW(&total_len, utf8_len, suffix_len) ||
total_len > MAX_PATH) {
git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%.*s'",
(int)path->size, path->ptr);
return -1;
}
#else
GIT_UNUSED(path);
GIT_UNUSED(suffix_len);
#endif
return 0;
}

Removing || total_len > MAX_PATH from the if clause fixed our problem.
This code is potentially duplicated by

libgit2/src/util/fs_path.h

Lines 683 to 709 in 42b5d85

/**
* Validate an on-disk path, taking into account that it will have a
* suffix appended (eg, `.lock`).
*/
GIT_INLINE(int) git_fs_path_validate_filesystem_with_suffix(
const char *path,
size_t path_len,
size_t suffix_len)
{
#ifdef GIT_WIN32
size_t path_chars, total_chars;
path_chars = git_utf8_char_length(path, path_len);
if (GIT_ADD_SIZET_OVERFLOW(&total_chars, path_chars, suffix_len) ||
total_chars > MAX_PATH) {
git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%s'", path);
return -1;
}
return 0;
#else
GIT_UNUSED(path);
GIT_UNUSED(path_len);
GIT_UNUSED(suffix_len);
return 0;
#endif
}

@pde-cds
Copy link
Author

pde-cds commented Jul 31, 2023

@ethomson Any thoughts about this?

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

2 participants