Bug 153154 - [patch][libarchive] fix error handling in mtree parsing code
Summary: [patch][libarchive] fix error handling in mtree parsing code
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
Depends on:
Reported: 2010-12-14 19:40 UTC by Mark Johnston
Modified: 2017-12-31 22:32 UTC (History)
0 users

See Also:

file.diff (621 bytes, patch)
2010-12-14 19:40 UTC, Mark Johnston
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Johnston 2010-12-14 19:40:04 UTC
When parsing an mtree file, libarchive expects to find a type for each file it encounters. If the type is not set, libarchive complains that the type keyword is missing _and_ that the mtree specification and the actual file type don't match. In the case that the type specification is omitted, I think that libarchive should only report the first error.

Fix: I attached a patch which has libarchive verify that MTREE_HAS_TYPE is set before potentially reporting that "mtree specification has a different type for ...".

After the patch:

$ tar -cvf out.tar @tar.mtree
tar: Error reading archive tar.mtree: Missing type keyword in mtree specification
tar: Error exit delayed from previous errors.

Patch attached with submission follows:
How-To-Repeat: $ ls
bar.c     foo.c     tar.mtree
$ cat tar.mtree
$ tar -cvf out.tar @tar.mtree
tar: Error reading archive tar.mtree: Missing type keyword in mtree specificationmtree specification has different type for foo.c
tar: Error exit delayed from previous errors.
$ echo $?
Comment 1 Mark Johnston 2010-12-14 20:15:57 UTC
Actually, I think the patch below is the proper way to handle this.
Otherwise, things like an invalid type specifier (e.g. type=filee) result
in the same problem as above.


diff --git a/lib/libarchive/archive_read_support_format_mtree.c b/lib/libarchive/archive_read_support_format_mtree.c
index 8643bb8..9295176 100644
--- a/lib/libarchive/archive_read_support_format_mtree.c
+++ b/lib/libarchive/archive_read_support_format_mtree.c
@@ -641,7 +641,7 @@ parse_file(struct archive_read *a, struct archive_entry *entry,
 		    archive_entry_filetype(entry) != AE_IFIFO)
 			mismatched_type = 1;
-		if (mismatched_type) {
+		if (mismatched_type && r == ARCHIVE_OK) {
 			if ((parsed_kws & MTREE_HAS_OPTIONAL) == 0) {
Comment 2 Mark Linimon freebsd_committer freebsd_triage 2011-10-10 05:40:04 UTC
Responsible Changed
From-To: freebsd-bugs->kientzle

Over to maintainer.
Comment 3 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:00:26 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped