Skip to content

Commit

Permalink
Merge remote-tracking branch 'source_repo/master' into ci
Browse files Browse the repository at this point in the history
  • Loading branch information
praiskup-mirroring committed Aug 21, 2023
2 parents d72845d + a9a8990 commit 01304b3
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 16 deletions.
5 changes: 4 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GNU tar NEWS - User visible changes. 2023-08-02
GNU tar NEWS - User visible changes. 2023-08-21
Please send GNU tar bug reports to <bug-tar@gnu.org>

version TBD
Expand Down Expand Up @@ -26,6 +26,9 @@ used, command output will be parsed using strptime(3).

* Bug fixes

** Fixed O(n^2) time complexity bug for large numbers of directories when
extracting with --delay-directory-restore or reading incremental archives.

** tar no longer uses alloca, fixing an unlikely stack overflow.


Expand Down
2 changes: 1 addition & 1 deletion gnulib
Submodule gnulib updated from 46f9c2 to 10ffa0
49 changes: 42 additions & 7 deletions src/extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ struct delayed_set_stat

static struct delayed_set_stat *delayed_set_stat_head;

/* Table of delayed stat updates hashed by path; null if none. */
static Hash_table *delayed_set_stat_table;

/* A link whose creation we have delayed. */
struct delayed_link
{
Expand Down Expand Up @@ -214,6 +217,20 @@ dl_compare (void const *a, void const *b)
return (da->dev == db->dev) & (da->ino == db->ino);
}

static size_t
ds_hash (void const *entry, size_t table_size)
{
struct delayed_set_stat const *ds = entry;
return hash_string (ds->file_name, table_size);
}

static bool
ds_compare (void const *a, void const *b)
{
struct delayed_set_stat const *dsa = a, *dsb = b;
return strcmp (dsa->file_name, dsb->file_name) == 0;
}

/* Set up to extract files. */
void
extr_init (void)
Expand Down Expand Up @@ -513,10 +530,15 @@ delay_set_stat (char const *file_name, struct tar_stat_info const *st,
size_t file_name_len = strlen (file_name);
struct delayed_set_stat *data;

for (data = delayed_set_stat_head; data; data = data->next)
if (strcmp (data->file_name, file_name) == 0)
break;
if (! (delayed_set_stat_table
|| (delayed_set_stat_table = hash_initialize (0, 0, ds_hash,
ds_compare, NULL))))
xalloc_die ();

struct delayed_set_stat key;
key.file_name = (char *) file_name;

data = hash_lookup (delayed_set_stat_table, &key);
if (data)
{
if (data->interdir)
Expand All @@ -541,6 +563,8 @@ delay_set_stat (char const *file_name, struct tar_stat_info const *st,
delayed_set_stat_head = data;
data->file_name_len = file_name_len;
data->file_name = xstrdup (file_name);
if (! hash_insert (delayed_set_stat_table, data))
xalloc_die ();
data->after_links = false;
if (st)
{
Expand Down Expand Up @@ -652,6 +676,7 @@ remove_delayed_set_stat (const char *fname)
if (chdir_current == data->change_dir
&& strcmp (data->file_name, fname) == 0)
{
hash_remove (delayed_set_stat_table, data);
free_delayed_set_stat (data);
if (prev)
prev->next = next;
Expand Down Expand Up @@ -1000,6 +1025,7 @@ apply_nonancestor_delayed_set_stat (char const *file_name, bool after_links)
}

delayed_set_stat_head = data->next;
hash_remove (delayed_set_stat_table, data);
free_delayed_set_stat (data);
}
}
Expand Down Expand Up @@ -1823,7 +1849,7 @@ extract_archive (void)
if (!delay_directory_restore_option)
{
int dir = chdir_current;
apply_nonancestor_delayed_set_stat (current_stat_info.file_name, 0);
apply_nonancestor_delayed_set_stat (current_stat_info.file_name, false);
chdir_do (dir);
}

Expand Down Expand Up @@ -1937,7 +1963,7 @@ apply_delayed_links (void)
for (struct delayed_link *ds = delayed_link_head; ds; ds = ds->next)
apply_delayed_link (ds);

if (false)
if (false && delayed_link_table)
{
/* There is little point to freeing, as we are about to exit,
and freeing is more likely to cause than cure trouble.
Expand All @@ -1953,15 +1979,24 @@ void
extract_finish (void)
{
/* First, fix the status of ordinary directories that need fixing. */
apply_nonancestor_delayed_set_stat ("", 0);
apply_nonancestor_delayed_set_stat ("", false);

/* Then, apply delayed links, so that they don't affect delayed
directory status-setting for ordinary directories. */
apply_delayed_links ();

/* Finally, fix the status of directories that are ancestors
of delayed links. */
apply_nonancestor_delayed_set_stat ("", 1);
apply_nonancestor_delayed_set_stat ("", true);

/* This table should be empty after apply_nonancestor_delayed_set_stat. */
if (false && delayed_set_stat_table)
{
/* There is little point to freeing, as we are about to exit,
and freeing is more likely to cause than cure trouble. */
hash_free (delayed_set_stat_table);
delayed_set_stat_table = NULL;
}
}

bool
Expand Down
14 changes: 7 additions & 7 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -963,16 +963,16 @@ sys_exec_setmtime_script (const char *script_name,
FATAL_ERROR ((0, errno, _("chdir failed")));
}

close (0);
close (1);
close (p[0]);
if (dup2 (p[1], STDOUT_FILENO) < 0)
FATAL_ERROR ((0, errno, _("dup2 failed")));
if (p[1] != STDOUT_FILENO)
close (p[1]);

if (open (dev_null, O_RDONLY) == -1)
close (STDIN_FILENO);
if (open (dev_null, O_RDONLY) != STDIN_FILENO)
open_error (dev_null);

if (dup2 (p[1], 1) == -1)
FATAL_ERROR ((0, errno, _("dup2 failed")));
close (p[0]);

priv_set_restore_linkdir ();
xexec (command);
}
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ TESTSUITE_AT = \
extrac23.at\
extrac24.at\
extrac25.at\
extrac26.at\
filerem01.at\
filerem02.at\
grow.at\
Expand Down
43 changes: 43 additions & 0 deletions tests/extrac26.at
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Test suite for GNU tar. -*- autotest -*-
# Copyright 2022-2023 Free Software Foundation, Inc.
#
# This file is part of GNU tar.
#
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([extract a large directory tree with --delay-directory-restore])
AT_KEYWORDS([extract extrac26])

AT_TAR_CHECK([
AT_SKIP_LARGE_FILES
AT_TIMEOUT_PREREQ

echo Creating dirtree
awk 'BEGIN { for (j = 0; j < 300; j++) for (k = 0; k < 300; k++) print "dirtree/" j "/" k }' | \
xargs mkdir -p

echo Creating archive
tar -cf archive.tar dirtree

echo Extracting archive
mkdir output
timeout 60 tar -xf archive.tar --delay-directory-restore -C output
],
[0],
[Creating dirtree
Creating archive
Extracting archive
],
[],[],[],[gnu])

AT_CLEANUP
1 change: 1 addition & 0 deletions tests/testsuite.at
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ m4_include([extrac22.at])
m4_include([extrac23.at])
m4_include([extrac24.at])
m4_include([extrac25.at])
m4_include([extrac26.at])

m4_include([backup01.at])

Expand Down

0 comments on commit 01304b3

Please sign in to comment.