From e95c0d752a5c14506a3db45de7d01c6462130d28 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 16 Aug 2020 13:39:04 +0200 Subject: Add a libtar test case for a completely filled link target field Signed-off-by: David Oberhollenzer --- tests/Makemodule.am | 9 ++- tests/tar/CREDITS | 4 + tests/tar/format-acceptance/link_filled.tar | Bin 0 -> 10240 bytes tests/tar/sqfs.sha512 | 1 + tests/tar_target_filled.c | 113 ++++++++++++++++++++++++++++ 5 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 tests/tar/format-acceptance/link_filled.tar create mode 100644 tests/tar_target_filled.c (limited to 'tests') diff --git a/tests/Makemodule.am b/tests/Makemodule.am index 543c3af..9694619 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -73,6 +73,11 @@ test_tar_ustar_SOURCES = tests/tar_ustar.c tests/test.h test_tar_ustar_LDADD = libtar.a libcompat.a test_tar_ustar_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar +test_tar_target_filled_SOURCES = tests/tar_target_filled.c tests/test.h +test_tar_target_filled_LDADD = libtar.a libcompat.a +test_tar_target_filled_CPPFLAGS = $(AM_CPPFLAGS) +test_tar_target_filled_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar + test_tar_sparse_gnu_SOURCES = tests/tar_sparse_gnu.c tests/test.h test_tar_sparse_gnu_LDADD = libtar.a libcompat.a test_tar_sparse_gnu_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar @@ -114,7 +119,7 @@ check_PROGRAMS += test_fstree_init test_filename_sane test_filename_sane_w32 check_PROGRAMS += test_tar_ustar test_tar_pax test_tar_gnu check_PROGRAMS += test_tar_sparse_gnu test_tar_sparse_gnu1 test_tar_sparse_gnu2 check_PROGRAMS += test_tar_xattr_bsd test_tar_xattr_schily -check_PROGRAMS += test_tar_xattr_schily_bin +check_PROGRAMS += test_tar_xattr_schily_bin test_tar_target_filled noinst_PROGRAMS += fstree_fuzz tar_fuzz @@ -125,7 +130,7 @@ TESTS += test_fstree_init test_filename_sane test_filename_sane_w32 TESTS += test_tar_ustar test_tar_pax TESTS += test_tar_gnu test_tar_sparse_gnu test_tar_sparse_gnu1 TESTS += test_tar_sparse_gnu2 test_tar_xattr_bsd test_tar_xattr_schily -TESTS += test_tar_xattr_schily_bin +TESTS += test_tar_xattr_schily_bin test_tar_target_filled if CORPORA_TESTS check_SCRIPTS += tests/cantrbry.sh tests/test_tar_sqfs.sh tests/pack_dir_root.sh diff --git a/tests/tar/CREDITS b/tests/tar/CREDITS index 6d55a59..776d93a 100644 --- a/tests/tar/CREDITS +++ b/tests/tar/CREDITS @@ -28,3 +28,7 @@ The following addtional files have been added: - xattr/xattr-shily-binary.tar Created from xattr/xattr-shily.tar by manually patching in a capability xattr key/value pair. + - tar/format-acceptance/link_filled.tar + Contributed in GitHub issue #64. A tar ball that contains a hard link + where the 100 byte target field is completely filled without containing + a null-terminator. diff --git a/tests/tar/format-acceptance/link_filled.tar b/tests/tar/format-acceptance/link_filled.tar new file mode 100644 index 0000000..9b80f89 Binary files /dev/null and b/tests/tar/format-acceptance/link_filled.tar differ diff --git a/tests/tar/sqfs.sha512 b/tests/tar/sqfs.sha512 index 51db821..bcdd245 100644 --- a/tests/tar/sqfs.sha512 +++ b/tests/tar/sqfs.sha512 @@ -17,6 +17,7 @@ d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e5 d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e54303df749e0267a606dd3631b4e91bb7cf91d8e71f329687 tests/tar/format-acceptance/v7.sqfs d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e54303df749e0267a606dd3631b4e91bb7cf91d8e71f329687 tests/tar/format-acceptance/pax.sqfs d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e54303df749e0267a606dd3631b4e91bb7cf91d8e71f329687 tests/tar/format-acceptance/ustar.sqfs +2f41b640b8aeec7f5e489fbbeef22bac118c8b1cb068b795433bb6e2f8e9a1ff4f11654e9617b9547ff34b4da7b8e660afcbe69cf630bc112c63693fc56d4e3e tests/tar/format-acceptance/link_filled.sqfs f97561018def03e8af41c3b479925052469d4a15645886c500a60a5caa835a1ad152b4e72912df52bde29e3645d6bda46002dd91982c3bc91ff844b5724d0917 tests/tar/user-group-largenum/gnu.sqfs b34d720e04bb7c1fb93c9c3520aa1c653992f9b80339de2416097d95603ab7bbc02ea46300823ec3808c0cfe37ed7477f110ac2eb0fd791832a93f3e5c8a1500 tests/tar/user-group-largenum/8-digit.sqfs f97561018def03e8af41c3b479925052469d4a15645886c500a60a5caa835a1ad152b4e72912df52bde29e3645d6bda46002dd91982c3bc91ff844b5724d0917 tests/tar/user-group-largenum/pax.sqfs diff --git a/tests/tar_target_filled.c b/tests/tar_target_filled.c new file mode 100644 index 0000000..6e8d923 --- /dev/null +++ b/tests/tar_target_filled.c @@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_target_filled.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "tar.h" +#include "test.h" + +#define STR(x) #x +#define STRVALUE(x) STR(x) + +#define TEST_PATH STRVALUE(TESTPATH) + +int main(void) +{ + tar_header_decoded_t hdr; + char buffer[16]; + FILE *fp; + + TEST_ASSERT(chdir(TEST_PATH) == 0); + + fp = test_open_read("format-acceptance/link_filled.tar"); + + /* "deep" directory hierarchy containg 2 files */ + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" + "20_characters_here03/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" + "20_characters_here03/20_characters_here04/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" + "20_characters_here03/20_characters_here04/" + "errored_file_tst"); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_ASSERT(read_retry("data0", fp, buffer, 5) == 0); + buffer[5] = '\0'; + TEST_STR_EQUAL(buffer, "test\n"); + TEST_ASSERT(skip_padding(fp, 5) == 0); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" + "20_characters_here03/20_characters_here04/" + "some_test_file"); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_ASSERT(read_retry("data1", fp, buffer, 5) == 0); + buffer[5] = '\0'; + TEST_STR_EQUAL(buffer, "test\n"); + TEST_ASSERT(skip_padding(fp, 5) == 0); + clear_header(&hdr); + + /* "deep" directory hierarchy containg a hard link */ + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/" + "20CharsForLnkTest003/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/" + "20CharsForLnkTest003/20CharsForLnkTest004/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/" + "20CharsForLnkTest003/20CharsForLnkTest004/" + "01234567890123456789"); + TEST_ASSERT(hdr.is_hard_link); + + TEST_STR_EQUAL(hdr.link_target, "20_characters_here01/" + "20_characters_here02/20_characters_here03/" + "20_characters_here04/errored_file_tst"); + clear_header(&hdr); + + /* end of file */ + TEST_ASSERT(read_header(fp, &hdr) > 0); + fclose(fp); + + return EXIT_SUCCESS; +} -- cgit v1.2.3