7zip: add SFX boundary tests

Add PE and ELF SFX fixtures for the SFX scanner boundary cases.

The PE fixture places an empty 7z archive at the final exact
32-byte scan window. The ELF fixture places ".data\0" at the final
valid section string-table position.

Register the fixtures for autotools distcheck.
This commit is contained in:
datauwu committed 2026-06-30 21:46:54 +08:00
1 parent 9046e753ca
commit 6333be32b8
4 files changed
+87

No files matched your search

+2
View File
@@ -893,6 +893,8 @@ libarchive_test_EXTRA_DIST=\
libarchive/test/test_read_format_7zip_malformed_numfiles_oom.7z.uu \
libarchive/test/test_read_format_7zip_packinfo_digests.7z.uu \
libarchive/test/test_read_format_7zip_ppmd.7z.uu \
libarchive/test/test_read_format_7zip_sfx_boundary_elf.elf.uu \
libarchive/test/test_read_format_7zip_sfx_boundary_pe.exe.uu \
libarchive/test/test_read_format_7zip_sfx_elf.elf.uu \
libarchive/test/test_read_format_7zip_sfx_elf64trunc.elf.uu \
libarchive/test/test_read_format_7zip_sfx_modified_pe.exe.uu \
+41
View File
@@ -1383,6 +1383,47 @@ DEFINE_TEST(test_read_format_7zip_sfx_elf)
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
static void
test_sfx_boundary_empty_7z(const char *refname)
{
struct archive_entry *ae = NULL;
struct archive *a;
const int bs = 10240;
extract_reference_file(refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
assertEqualIntA(a, ARCHIVE_OK,
archive_read_open_filename(a, refname, bs));
assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
assertEqualInt(0, archive_file_count(a));
assertEqualIntA(a, ARCHIVE_FORMAT_7ZIP, archive_format(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
DEFINE_TEST(test_read_format_7zip_sfx_boundary_pe)
{
/*
* The embedded empty 7z archive starts at the final exact
* 32-byte scan window after the PE overlay offset.
*/
test_sfx_boundary_empty_7z(
"test_read_format_7zip_sfx_boundary_pe.exe");
}
DEFINE_TEST(test_read_format_7zip_sfx_boundary_elf)
{
/*
* The ELF section string table contains "\0.data\0", so
* ".data\0" starts at the final valid string-table position.
*/
test_sfx_boundary_empty_7z(
"test_read_format_7zip_sfx_boundary_elf.elf");
}
/*
* A truncated ELF 64-bit MSB file.
*/
@@ -0,0 +1,22 @@
begin 644 test_read_format_7zip_sfx_boundary_elf.elf
M?T5,1@(!`0````````````(`/@`!```````````````````````````"````
M`````````$```````$```P`!```N9&%T80``````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````````````````,`````
M````````````````````0``````````'````````````````````````````
M``````````````$````!```````````````````````````#````````(```
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````-WJ\KR<<``2-F]4/````````````````````````````````````````
6````````````````````````````````
`
end
@@ -0,0 +1,22 @@
begin 644 test_read_format_7zip_sfx_boundary_pe.exe
M35H`````````````````````````````````````````````````````````
M````````````````````0````%!%``!,`0$`````````````````X``"````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````+G1E
M>'0````````````````!`````@``````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04$W>KRO)QP`!(V;
6U0\`````````````````````````````
`
end