All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] erofs-utils: tar: support archives without end-of-archive entry
@ 2025-09-29 13:32 Ivan Mikheykin
  2025-09-29 14:50 ` Gao Xiang
  2025-10-01 17:13 ` [PATCH v2] " Ivan Mikheykin
  0 siblings, 2 replies; 7+ messages in thread
From: Ivan Mikheykin @ 2025-09-29 13:32 UTC (permalink / raw)
  To: linux-erofs; +Cc: Ivan Mikheykin

Tar standard https://www.gnu.org/software/tar/manual/html_node/Standard.html
says that archive "terminated by an end-of-archive entry,
which consists of two 512 blocks of zero bytes".

Is also says:

"A reasonable system should write such end-of-file marker at the end
of an archive, but must not assume that such a block exists when
reading an archive. In particular, GNU tar does not treat missing
end-of-file marker as an error and silently ignores the fact."

It is rare for erofs to encounter such problem, as images are mostly
built with docker or buildah. But if you create image using tar library
in Golang directly uploading layers to registry, you'll get tar layers
without end-of-archive block. Running containers with such images will
trigger this error during extraction:

mkfs.erofs --tar=f --aufs --quiet -Enoinline_data test.erofs test-no-end.tar
<E> erofs: failed to read header block @ 42496
<E> erofs: 	Could not format the device : [Error 5] Input/output error

This patch fixes the problem by assuming that eof is equal to the end-of-archive.

Reproducible tar without end-of-archive (base64-encoded gzipped blob):
H4sICKVi2mgAA3Rlc3QtMTAtMi1ibG9ja3MudGFyAAtzDQr29PdjoCUwAAIzExMwbW5mCqYN
jQzANBgYGTEYmhqYmpqamRoaGTMYGBqaGJkyKBjQ1FVQUFpcklikoMCQkpmYll9ahFNdYkpu
Zh49HERfYKhnoWdowGVkYGSqa2Cua2jKNdAuGgX0BADwFwqsAAQAAA==

Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
---
 lib/tar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/tar.c b/lib/tar.c
index 72c12ed..128f8b0 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -740,7 +740,7 @@ restart:
 	tar_offset = tar->offset;
 	ret = erofs_iostream_read(&tar->ios, (void **)&th, sizeof(*th));
 	if (ret != sizeof(*th)) {
-		if (tar->headeronly_mode || tar->ddtaridx_mode) {
+		if (tar->headeronly_mode || tar->ddtaridx_mode || tar->ios.feof) {
 			ret = 1;
 			goto out;
 		}
-- 
2.39.3 (Apple Git-146)



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-10-02  0:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-29 13:32 [PATCH] erofs-utils: tar: support archives without end-of-archive entry Ivan Mikheykin
2025-09-29 14:50 ` Gao Xiang
2025-09-30  7:42   ` Ivan Mikheykin
2025-09-30  8:01     ` Gao Xiang
2025-09-30  8:08       ` Gao Xiang
2025-10-01 17:13 ` [PATCH v2] " Ivan Mikheykin
2025-10-02  0:39   ` Gao Xiang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.