Repository navigation
Ticket #5227: assorted tarfs fixes #5228
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
Open
zyv
wants to merge
17
commits into
master
Choose a base branch
from
5227_tarfs_fixes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
652b4ae
Ticket #5227: tests: add tarfs tests for pax sparse members
zyv eb4ef55
tarfs: detect sparse members in pax archives
zyv 711d7a5
tarfs: read sparse data after the sparse map
zyv ed05b07
tarfs: fix crash on the pax sparse format 0.0
zyv f985bea
tarfs: round sparse chunks up to whole blocks
zyv 942fd1f
tarfs: don't allocate the sparse map by the count from the archive
zyv ad078c2
tarfs: don't abort on headers that don't fit into memory
zyv de5d102
vfs: give generated archive directories the time of the archive
zyv 286ccf9
tarfs: apply a directory entry that comes after its contents
zyv 32fb823
fixup! tarfs: fix crash on the pax sparse format 0.0
zyv 65c14ad
fixup! tarfs: fix crash on the pax sparse format 0.0
zyv addf8f7
tarfs: show an error message on a cascade of bad headers
zyv 47b6bdc
amend! tarfs: show an error message on a cascade of bad headers
zyv 0b7515d
fixup! tarfs: detect sparse members in pax archives
zyv 9aa4b41
fixup! tarfs: don't allocate the sparse map by the count from the arc…
zyv f371ec3
tarfs: don't read old blocks after the end of the archive
zyv 5779ece
tarfs: show an error message for a cut-off archive
zyv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -251,7 +251,7 @@ tar_calc_sparse_offsets (struct vfs_s_inode *inode) | |
|
|
||
| sp = &g_array_index (sm, struct sp_array, i); | ||
| sp->arch_offset = begin; | ||
| begin += BLOCKSIZE * (sp->numbytes / BLOCKSIZE + sp->numbytes % BLOCKSIZE); | ||
| begin += BLOCKSIZE * (sp->numbytes / BLOCKSIZE + (sp->numbytes % BLOCKSIZE != 0)); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -271,19 +271,27 @@ tar_skip_member (tar_super_t *archive, struct vfs_s_inode *inode) | |
|
|
||
| if (current_stat_info.is_sparse) | ||
| { | ||
| if (inode != NULL) | ||
| inode->data_offset = BLOCKSIZE * tar_current_block_ordinal (archive); | ||
| off_t data_offset = BLOCKSIZE * tar_current_block_ordinal (archive); | ||
|
|
||
| (void) tar_sparse_skip_file (archive, ¤t_stat_info); | ||
| (void) tar_sparse_skip_file (archive, ¤t_stat_info, &data_offset); | ||
|
|
||
| if (inode != NULL) | ||
| { | ||
| inode->data_offset = data_offset; | ||
|
|
||
| // use vfs_s_inode::user_data to keep the sparse map | ||
| inode->user_data = current_stat_info.sparse_map; | ||
| current_stat_info.sparse_map = NULL; | ||
|
|
||
| // without chunks, e.g. if the archive ends in the map, the whole member is a hole | ||
| if (inode->user_data == NULL) | ||
| inode->user_data = g_array_new (FALSE, FALSE, sizeof (struct sp_array)); | ||
|
|
||
| tar_calc_sparse_offsets (inode); | ||
| } | ||
|
|
||
| // FALSE if the map or the data is cut off | ||
| return !hit_eof; | ||
| } | ||
| else if (save_typeflag != DIRTYPE) | ||
| { | ||
|
|
@@ -564,7 +572,19 @@ tar_insert_entry (struct vfs_class *me, struct vfs_s_super *archive, union block | |
| { | ||
| entry = VFS_SUBCLASS (me)->find_entry (me, parent, p, LINK_NO_FOLLOW, FL_NONE); | ||
| if (entry != NULL) | ||
| { | ||
| if (S_ISDIR (entry->ino->st.st_mode)) | ||
| { | ||
| entry->ino->st.st_mode = current_stat_info.stat.st_mode; | ||
| entry->ino->st.st_uid = current_stat_info.stat.st_uid; | ||
| entry->ino->st.st_gid = current_stat_info.stat.st_gid; | ||
| vfs_zero_stat_times (&entry->ino->st); | ||
| entry->ino->st.st_mtime = current_stat_info.mtime.tv_sec; | ||
| entry->ino->st.st_atime = current_stat_info.atime.tv_sec; | ||
| entry->ino->st.st_ctime = current_stat_info.ctime.tv_sec; | ||
| } | ||
| return HEADER_SUCCESS; | ||
| } | ||
| } | ||
|
|
||
| *inode = vfs_s_new_inode (me, archive, ¤t_stat_info.stat); | ||
|
|
@@ -599,6 +619,12 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive) | |
| current_header = header; | ||
| if (header == NULL) | ||
| { | ||
| // the archive is cut off after an extended header or a long name of a member | ||
| if (hit_eof | ||
| && (next_long_name != NULL || next_long_link != NULL | ||
| || current_stat_info.xhdr.buffer != NULL)) | ||
| message (D_ERROR, MSG_ERROR, _ ("Unexpected EOF on archive file")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would be more natural to say "Unexpected end of archive file". or just "Truncated archive". |
||
|
|
||
| status = HEADER_END_OF_FILE; | ||
| goto ret; | ||
| } | ||
|
|
@@ -635,14 +661,18 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive) | |
|
|
||
| if (ckd_add (&size, current_stat_info.stat.st_size, 2 * BLOCKSIZE - 1)) | ||
| { | ||
| message (D_ERROR, MSG_ERROR, _ ("Inconsistent tar archive")); | ||
| status = HEADER_FAILURE; | ||
| goto ret; | ||
| } | ||
|
|
||
| size -= size % BLOCKSIZE; | ||
|
|
||
| header_copy = g_malloc (size + 1); | ||
| header_copy = g_try_malloc (size + 1); | ||
| if (header_copy == NULL) | ||
| { | ||
| status = HEADER_FAILURE; | ||
| goto ret; | ||
| } | ||
|
|
||
| if (header->header.typeflag == GNUTYPE_LONGNAME) | ||
| { | ||
|
|
@@ -666,7 +696,6 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive) | |
| data_block = tar_find_next_block (arch); | ||
| if (data_block == NULL) | ||
| { | ||
| message (D_ERROR, MSG_ERROR, _ ("Unexpected EOF on archive file")); | ||
| status = HEADER_FAILURE; | ||
| goto ret; | ||
| } | ||
|
|
@@ -684,12 +713,13 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive) | |
| } | ||
| else if (header->header.typeflag == XHDTYPE || header->header.typeflag == SOLARIS_XHDTYPE) | ||
| { | ||
| if (arch->type == TAR_UNKNOWN) | ||
| // the first header of a pax archive is this extended header, which has the ustar | ||
| // magic: like GNU tar, treat an archive with an extended header as pax, not ustar | ||
| if (arch->type == TAR_UNKNOWN || arch->type == TAR_USTAR) | ||
| arch->type = TAR_POSIX; | ||
| if (!tar_xheader_read (arch, ¤t_stat_info.xhdr, header, | ||
| OFF_FROM_HEADER (header->header.size))) | ||
| { | ||
| message (D_ERROR, MSG_ERROR, _ ("Unexpected EOF on archive file")); | ||
| status = HEADER_FAILURE; | ||
| goto ret; | ||
| } | ||
|
|
@@ -703,13 +733,12 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive) | |
| arch->type = TAR_POSIX; | ||
|
|
||
| memset (&xhdr, 0, sizeof (xhdr)); | ||
| tar_xheader_read (arch, &xhdr, header, OFF_FROM_HEADER (header->header.size)); | ||
| ok = tar_xheader_decode_global (&xhdr); | ||
| ok = tar_xheader_read (arch, &xhdr, header, OFF_FROM_HEADER (header->header.size)) | ||
| && tar_xheader_decode_global (&xhdr); | ||
| tar_xheader_destroy (&xhdr); | ||
|
|
||
| if (!ok) | ||
| { | ||
| message (D_ERROR, MSG_ERROR, _ ("Inconsistent tar archive")); | ||
| status = HEADER_FAILURE; | ||
| goto ret; | ||
| } | ||
|
|
@@ -805,10 +834,7 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive) | |
|
|
||
| status = tar_insert_entry (me, archive, header, &inode); | ||
| if (status != HEADER_SUCCESS) | ||
| { | ||
| message (D_ERROR, MSG_ERROR, _ ("Inconsistent tar archive")); | ||
| goto ret; | ||
| } | ||
|
|
||
| if (recent_long_name == next_long_name) | ||
| recent_long_name = NULL; | ||
|
|
@@ -819,7 +845,11 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive) | |
| if (tar_skip_member (arch, inode)) | ||
| status = HEADER_SUCCESS; | ||
| else if (hit_eof) | ||
| { | ||
| // the header is good, but the data is cut off: keep the member, and end the archive | ||
| message (D_ERROR, MSG_ERROR, _ ("Unexpected EOF on archive file")); | ||
| status = HEADER_END_OF_FILE; | ||
| } | ||
| else | ||
| status = HEADER_FAILURE; | ||
| } | ||
|
|
@@ -1006,13 +1036,15 @@ tar_open_archive (struct vfs_s_super *archive, const vfs_path_t *vpath, | |
|
|
||
| case HEADER_ZERO_BLOCK: | ||
| case HEADER_SUCCESS: | ||
| // Skipping to next header. | ||
| break; // AB: FIXME | ||
| // Skipping to next header: report it once for the whole cascade. | ||
| message (D_ERROR, MSG_ERROR, | ||
| hit_eof ? _ ("Unexpected EOF on archive file") | ||
| : _ ("Inconsistent tar archive")); | ||
| break; | ||
|
|
||
| case HEADER_END_OF_FILE: | ||
| case HEADER_FAILURE: | ||
| // We are in the middle of a cascade of errors. | ||
| // AB: FIXME: TODO: show an error message here | ||
| // We are in the middle of a cascade of errors, which is already reported. | ||
| return -1; | ||
|
|
||
| default: | ||
|
|
@@ -1187,6 +1219,13 @@ tar_lseek_sparse (vfs_file_handler_t *fh, off_t offset) | |
| break; | ||
|
|
||
| case 0: | ||
| if (sm->len == 0) | ||
| { | ||
| // without chunks, the whole member is a hole | ||
| offset = fh->ino->data_offset; | ||
| break; | ||
| } | ||
|
|
||
| chunk = &g_array_index (sm, struct sp_array, sm->len - 1); | ||
| // FIXME: can we seek beyond tar archive EOF here? | ||
| offset = chunk->arch_offset + chunk->numbytes; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,3 +12,7 @@ endif | |
| if ENABLE_VFS_FTP | ||
| SUBDIRS += ftpfs | ||
| endif | ||
|
|
||
| if ENABLE_VFS_TAR | ||
| SUBDIRS += tar | ||
| endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| PACKAGE_STRING = "/src/vfs/tar" | ||
|
|
||
| AM_CPPFLAGS = \ | ||
| $(GLIB_CFLAGS) \ | ||
| -I$(top_srcdir) \ | ||
| @CHECK_CFLAGS@ | ||
|
|
||
| LDADD = \ | ||
| $(top_builddir)/src/libinternal.la \ | ||
| $(top_builddir)/lib/libmc.la \ | ||
| @CHECK_LIBS@ | ||
|
|
||
| TESTS = \ | ||
| tar_open_archive | ||
|
|
||
| check_PROGRAMS = $(TESTS) | ||
|
|
||
| tar_open_archive_SOURCES = \ | ||
| tar_open_archive.c |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.