libarchive / libarchive

Multi-format archive and compression library

Home Page:http://www.libarchive.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tar crashes when using -H or -L options with wildcards in Windows

jet2jet opened this issue · comments

commented

Basic Information

  • Version of libarchive: 3.7.4 (or HEAD of libarchive repo)
  • How you obtained it: build from source, and a binary bundled in Windows (version is 3.6.2)
  • Operating system and version: Windows 11 (10.0.22621.3447)
  • What compiler and/or IDE you are using (include version): Visual Studio 2022 (17.7.0) / Microsoft C/C++ Compiler 19.37.32822

Description of the problem you are seeing:

  • When executing tar cf test.tar -L *.*, tar abnormally exits with error code (-1073741819 == 0xC0000005).

How the libarchive developers can reproduce your problem:

  • Simply type tar cf test.tar -L *.* or tar cf test.tar -H *.*
commented

I debugged and found that the following line generates an exception (t->current is null):

for (te = t->current->parent; te != NULL; te = te->parent) {

When using wildcards, the following code will not store t->current, and it would be the cause of the above exception.

if (t->stack->flags & needsFirstVisit) {
wchar_t *d = t->stack->name.s;
t->stack->flags &= ~needsFirstVisit;
if (!(d[0] == L'/' && d[1] == L'/' &&
d[2] == L'?' && d[3] == L'/') &&
(wcschr(d, L'*') || wcschr(d, L'?'))) {
r = tree_dir_next_windows(t, d);
if (r == 0)
continue;
return (r);
} else {
HANDLE h = FindFirstFileW(t->stack->full_path.s, &t->_findData);
if (h == INVALID_HANDLE_VALUE) {
la_dosmaperr(GetLastError());
t->tree_errno = errno;
t->visit_type = TREE_ERROR_DIR;
return (t->visit_type);
}
t->findData = &t->_findData;
FindClose(h);
}
/* Top stack item needs a regular visit. */
t->current = t->stack;
tree_append(t, t->stack->name.s,
archive_strlen(&(t->stack->name)));
//t->dirname_length = t->path_length;
//tree_pop(t);
t->stack->flags &= ~needsFirstVisit;
return (t->visit_type = TREE_REGULAR);
} else if (t->stack->flags & needsDescent) {