Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault when using archive_entry_set_pathname_utf8() with non-ASCII filenames #2233

Closed
theGreatWhiteShark opened this issue Jun 14, 2024 · 3 comments

Comments

@theGreatWhiteShark
Copy link

Hi,

I'm on libarchive 3.7.2 (6468cd1) (but see a similar crash in 3.6.2)

PASS: libarchive_test
PASS: bsdtar_test
PASS: bsdcpio_test
PASS: bsdcat_test
PASS: bsdunzip_test
============================================================================
Testsuite summary for libarchive 3.7.2
============================================================================
# TOTAL: 5
# PASS:  5
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0

and want to create archives with non-ASCII paths containing non-ASCII files.

With C and Qt I do something similar to

	QStringList filesUsed;
	filesUsed << "/tmp/ếИ£TestKit越/drumkit.xml"
		<< "/tmp/ếИ£TestKit越/snare.wav"
		<< "/tmp/ếИ£TestKit越/æÿка́зка.wav";
	const QString sTargetPath =  "/tmp/ếИ£TestKit越.h2drumkit";
	const QString sDrumkitName =  "ếИ£TestKit越";

	struct archive *a;
	struct archive_entry *entry;
	struct stat st;
	char buff[ 8192 ];
	int len;

	archive_write_new();

#if ARCHIVE_VERSION_NUMBER < 3000000
	archive_write_set_compression_gzip( a );
#else
	archive_write_add_filter_gzip( a );
#endif

	archive_write_set_format_pax_restricted( a );

	archive_write_open_filename( a, sTargetPath.toUtf8().constData() );

	for ( const auto& sFilename : filesUsed ) {
		QFileInfo ffileInfo( sFilename );
		const QString sTargetFilename =
			sDrumkitName   "/"   ffileInfo.fileName();

		stat( sFilename.toUtf8().constData(), &st );
		entry = archive_entry_new();
		archive_entry_set_pathname_utf8(entry, sTargetFilename.toUtf8().constData());
		archive_entry_set_size(entry, st.st_size);
		archive_entry_set_filetype(entry, AE_IFREG);
		archive_entry_set_perm(entry, 0644);
		archive_write_header(a, entry);
		f = fopen( sFilename.toUtf8().constData(), "rb" );
		len = fread(buff, sizeof(char), sizeof(buff), f);
		while ( len > 0 ) {
				archive_write_data(a, buff, len);
				len = fread(buff, sizeof(char), sizeof(buff), f);
		}
		fclose(f);
		archive_entry_free(entry);
	}
	archive_write_close(a);

#if ARCHIVE_VERSION_NUMBER < 3000000
	archive_write_finish(a);
#else
	archive_write_free(a);
#endif

But it crashes on the line of

archive_write_header(a, entry);

with the following backtrace

Thread 1 "tests" received signal SIGSEGV, Segmentation fault.
__strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:76
76	../sysdeps/x86_64/multiarch/strlen-avx2.S: No such file or directory.
(gdb) bt
#0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:76
#1  0x00007ffff68e438e in add_pax_attr (value=0x0, key=0x7ffff68f5d0c "path", as=0x5555559f50e8) at libarchive/archive_write_set_format_pax.c:311
#2  archive_write_pax_header (a=0x5555558b2f10, entry_original=0x555555a54fa0) at libarchive/archive_write_set_format_pax.c:1014
#3  0x00007ffff68c51a0 in _archive_write_header (_a=0x5555558b2f10, entry=0x555555a54fa0) at libarchive/archive_write.c:775

When using archive_entry_set_pathname instead of archive_entry_set_pathname_utf8 there is no segfault but I only get a bricked archive since the paths aren't handled properly.

Do I do something wrong in here? And is there another way to provide full UTF8 support when reading/writing archives? (Ideally a solution that also works for older versions of libarchive)

@evelikov
Copy link
Collaborator

Currently one needs to explicitly set an UTF-8 locale - either in the user or the program itself. See #587 for more details.

Our tests have some examples how to do that.

@evelikov
Copy link
Collaborator

In the small chance that it still doesn't work, please reopen and provide details more details. Output of locale, available locales present on the system, example archive, OS and filesystem details, etc.

@theGreatWhiteShark
Copy link
Author

Thanks a lot! Seems to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants