From 3d8415151b67ac1df1ecb370ad0ab9c808d004f0 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 28 Jun 2019 11:32:50 +0200 Subject: Add test case for tar large file size support Signed-off-by: David Oberhollenzer --- tests/Makemodule.am | 7 ++- tests/tar/CREDITS | 3 ++ tests/tar/file-size/12-digit.tar | Bin 0 -> 2048 bytes tests/tar/file-size/12-digit.tar.gz.gz | Bin 99861 -> 0 bytes tests/tar/file-size/ZIPBOMB-WARNING | 6 --- tests/tar/file-size/gnu.tar | Bin 0 -> 2048 bytes tests/tar/file-size/gnu.tar.gz.gz | Bin 99827 -> 0 bytes tests/tar/file-size/pax.tar | Bin 0 -> 2048 bytes tests/tar/file-size/pax.tar.gz.gz | Bin 100215 -> 0 bytes tests/tar_big_size.c | 79 +++++++++++++++++++++++++++++++++ 10 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 tests/tar/file-size/12-digit.tar delete mode 100644 tests/tar/file-size/12-digit.tar.gz.gz delete mode 100644 tests/tar/file-size/ZIPBOMB-WARNING create mode 100644 tests/tar/file-size/gnu.tar delete mode 100644 tests/tar/file-size/gnu.tar.gz.gz create mode 100644 tests/tar/file-size/pax.tar delete mode 100644 tests/tar/file-size/pax.tar.gz.gz create mode 100644 tests/tar_big_size.c (limited to 'tests') diff --git a/tests/Makemodule.am b/tests/Makemodule.am index 8bf818e..44c6eda 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -38,6 +38,10 @@ test_tar_formats_SOURCES = tests/tar_formats.c test_tar_formats_LDADD = libtar.a libutil.a test_tar_formats_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar +test_tar_big_size_SOURCES = tests/tar_big_size.c +test_tar_big_size_LDADD = libtar.a libutil.a +test_tar_big_size_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar + test_tar_long_paths_SOURCES = tests/tar_long_paths.c test_tar_long_paths_LDADD = libtar.a libutil.a test_tar_long_paths_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar @@ -55,10 +59,11 @@ check_PROGRAMS += test_mknode_reg test_mknode_dir test_gen_inode_table check_PROGRAMS += test_add_by_path test_get_path test_fstree_sort check_PROGRAMS += test_fstree_from_file test_fstree_init test_fstree_xattr check_PROGRAMS += test_tar_formats test_tar_long_paths test_tar_mtime -check_PROGRAMS += test_tar_large_uid +check_PROGRAMS += test_tar_large_uid test_tar_big_size TESTS += test_canonicalize_name test_mknode_simple test_mknode_slink TESTS += test_mknode_reg test_mknode_dir test_gen_inode_table TESTS += test_add_by_path test_get_path test_fstree_sort test_fstree_from_file TESTS += test_fstree_init test_fstree_xattr test_tar_formats TESTS += test_tar_long_paths test_tar_mtime test_tar_large_uid +TESTS += test_tar_big_size diff --git a/tests/tar/CREDITS b/tests/tar/CREDITS index 32014fc..e4b19b4 100644 --- a/tests/tar/CREDITS +++ b/tests/tar/CREDITS @@ -20,3 +20,6 @@ for those features: - longe user + group names - sun tar samples - star samples + +In addition to that, the files in "file-size" are truncated, since we are only +interested in parsing the header. diff --git a/tests/tar/file-size/12-digit.tar b/tests/tar/file-size/12-digit.tar new file mode 100644 index 0000000..a6b3553 Binary files /dev/null and b/tests/tar/file-size/12-digit.tar differ diff --git a/tests/tar/file-size/12-digit.tar.gz.gz b/tests/tar/file-size/12-digit.tar.gz.gz deleted file mode 100644 index aaa69e3..0000000 Binary files a/tests/tar/file-size/12-digit.tar.gz.gz and /dev/null differ diff --git a/tests/tar/file-size/ZIPBOMB-WARNING b/tests/tar/file-size/ZIPBOMB-WARNING deleted file mode 100644 index e530637..0000000 --- a/tests/tar/file-size/ZIPBOMB-WARNING +++ /dev/null @@ -1,6 +0,0 @@ -WARNING! - -The inner compressed tarballs in this directory are 8 GiB of size each. -Be careful not to decompress them accidentally without preparing -appropriate backing store (or having the decompressor smart about sparse -files). diff --git a/tests/tar/file-size/gnu.tar b/tests/tar/file-size/gnu.tar new file mode 100644 index 0000000..aad726f Binary files /dev/null and b/tests/tar/file-size/gnu.tar differ diff --git a/tests/tar/file-size/gnu.tar.gz.gz b/tests/tar/file-size/gnu.tar.gz.gz deleted file mode 100644 index 6ae4342..0000000 Binary files a/tests/tar/file-size/gnu.tar.gz.gz and /dev/null differ diff --git a/tests/tar/file-size/pax.tar b/tests/tar/file-size/pax.tar new file mode 100644 index 0000000..e391fee Binary files /dev/null and b/tests/tar/file-size/pax.tar differ diff --git a/tests/tar/file-size/pax.tar.gz.gz b/tests/tar/file-size/pax.tar.gz.gz deleted file mode 100644 index 7c887d6..0000000 Binary files a/tests/tar/file-size/pax.tar.gz.gz and /dev/null differ diff --git a/tests/tar_big_size.c b/tests/tar_big_size.c new file mode 100644 index 0000000..3b5b557 --- /dev/null +++ b/tests/tar_big_size.c @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +#include "util.h" +#include "tar.h" + +#include +#include +#include +#include +#include +#include + +#define STR(x) #x +#define STRVALUE(x) STR(x) + +#define TEST_PATH STRVALUE(TESTPATH) + +static int open_read(const char *path) +{ + int fd = open(path, O_RDONLY); + + if (fd < 0) { + perror(path); + exit(EXIT_FAILURE); + } + + return fd; +} + +int main(void) +{ + tar_header_decoded_t hdr; + int fd; + + assert(chdir(TEST_PATH) == 0); + + fd = open_read("file-size/pax.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 8589934592); + assert(hdr.sb.st_mtime == 1542959190); + assert(hdr.sb.st_atime == 1542959522); + assert(hdr.sb.st_ctime == 1542959190); + assert(strcmp(hdr.name, "big-file.bin") == 0); + assert(!hdr.unknown_record); + clear_header(&hdr); + close(fd); + + fd = open_read("file-size/gnu.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 8589934592); + assert(hdr.sb.st_mtime == 013375730126); + assert(hdr.sb.st_atime == 013375730126); + assert(hdr.sb.st_ctime == 013375730126); + assert(strcmp(hdr.name, "big-file.bin") == 0); + assert(!hdr.unknown_record); + clear_header(&hdr); + close(fd); + + fd = open_read("file-size/12-digit.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 8589934592); + assert(hdr.sb.st_mtime == 013375730126); + assert(hdr.sb.st_atime == 013375730126); + assert(hdr.sb.st_ctime == 013375730126); + assert(strcmp(hdr.name, "big-file.bin") == 0); + assert(!hdr.unknown_record); + clear_header(&hdr); + close(fd); + + return EXIT_SUCCESS; +} -- cgit v1.2.3