Merge pull request #3278 from uchiha-bug-hunter/cpio-trailer-uaf

cpio: add regression test for symlink-trailer end-of-archive check
This commit is contained in:
Dustin L. Howett authored and GitHub committed 2026-07-13 12:03:30 -05:00
commit a6a899d655
4 files changed
+2980

No files matched your search

+2
View File
@@ -512,6 +512,7 @@ libarchive_test_SOURCES= \
libarchive/test/test_read_format_cpio_svr4_gzip.c \
libarchive/test/test_read_format_cpio_svr4_gzip_rpm.c \
libarchive/test/test_read_format_cpio_svr4c_Z.c \
libarchive/test/test_read_format_cpio_symlink_trailer.c \
libarchive/test/test_read_format_empty.c \
libarchive/test/test_read_format_gtar_filename.c \
libarchive/test/test_read_format_gtar_gz.c \
@@ -937,6 +938,7 @@ libarchive_test_EXTRA_DIST=\
libarchive/test/test_read_format_cpio_filename_utf8_ru.cpio.uu \
libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.rpm.uu \
libarchive/test/test_read_format_cpio_svr4_gzip_rpm.rpm.uu \
libarchive/test/test_read_format_cpio_symlink_trailer.cpio.uu \
libarchive/test/test_read_format_gtar_filename_cp866.tar.Z.uu \
libarchive/test/test_read_format_gtar_filename_eucjp.tar.Z.uu \
libarchive/test/test_read_format_gtar_filename_koi8r.tar.Z.uu \
+1
View File
@@ -141,6 +141,7 @@ IF(ENABLE_TEST)
test_read_format_cpio_svr4_gzip.c
test_read_format_cpio_svr4_gzip_rpm.c
test_read_format_cpio_svr4c_Z.c
test_read_format_cpio_symlink_trailer.c
test_read_format_empty.c
test_read_format_gtar_filename.c
test_read_format_gtar_gz.c
@@ -0,0 +1,58 @@
/*-
* Copyright (c) 2026 Kaif Khan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
/*
* The cpio reader reads an entry's name into a read-ahead buffer and holds
* that pointer to compare the name against "TRAILER!!!" (end of archive).
* For a symlink entry the link body is read first, and a large body can grow
* (and free) the read-ahead buffer, leaving the name pointer dangling before
* the trailer comparison.
*
* The reference archive is a single newc entry: a symlink named "TRAILER!!!"
* with a 128 KiB body. Reading it in small blocks assembles the name in the
* reader's copy buffer, which the symlink body read then reallocates; the
* trailer must still be detected without touching freed memory.
*/
DEFINE_TEST(test_read_format_cpio_symlink_trailer)
{
const char *name = "test_read_format_cpio_symlink_trailer.cpio";
struct archive_entry *ae;
struct archive *a;
extract_reference_file(name);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_cpio(a));
/* Small block size so the name is assembled in the reader's copy
* buffer, which the symlink body read then reallocates. */
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 13));
/* The "TRAILER!!!" entry ends the archive. */
assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
File diff suppressed because it is too large. Load diff