linux – CentOS Tar: A strange bug in doing nested tar -zcf, which makes compressed pack size abnormal with “tar”

When I practiced “tar”, I accidentally met a bug:
When doing nested operation that ‘tar -zcf’ a folder and dump the compressed pack under the folder, if the target name includes ‘dir’, it will cause something strange.
Here’s the operations:

  1. Initially, the dir tree and some text file contents printed with ‘ll’:
[planet@planetCentOS01 tar_bug_test]$ tree .
.
`-- ggyy
    |-- services
    `-- services_reverse

1 directory, 2 files

[planet@planetCentOS01 tar_bug_test]$ ll * -R
ggyy:
total 1312
-rw-r--r--. 1 planet planet 670293 Feb 14 22:09 services
-rw-rw-r--. 1 planet planet 670293 Feb 14 23:41 services_reverse

  1. First show you the normal situation (without ‘dir’ in target name), where you can find the size of pack doesn’t change except a little bit:
[planet@planetCentOS01 tar_bug_test]$ ll ggyy
total 1312
-rw-r--r--. 1 planet planet 670293 Feb 14 22:09 services
-rw-rw-r--. 1 planet planet 670293 Feb 14 23:41 services_reverse

[planet@planetCentOS01 tar_bug_test]$ **tar -zcvf ggyy/dis.tar.gz ggyy/**
ggyy/
ggyy/services
ggyy/services_reverse
tar: ggyy: file changed as we read it

[planet@planetCentOS01 tar_bug_test]$ ll ggyy
total 1576
**-rw-rw-r--. 1 planet planet 269683 Feb 15 00:04 dis.tar.gz**
-rw-r--r--. 1 planet planet 670293 Feb 14 22:09 services
-rw-rw-r--. 1 planet planet 670293 Feb 14 23:41 services_reverse

[planet@planetCentOS01 tar_bug_test]$ **tar -zcvf ggyy/dis.tar.gz ggyy/**
ggyy/
ggyy/dis.tar.gz
ggyy/services
ggyy/services_reverse

[planet@planetCentOS01 tar_bug_test]$ ll ggyy
total 1576
**-rw-rw-r--. 1 planet planet 269787 Feb 15 00:04 dis.tar.gz**
-rw-r--r--. 1 planet planet 670293 Feb 14 22:09 services
-rw-rw-r--. 1 planet planet 670293 Feb 14 23:41 services_reverse

  1. When repeat the operation with word ‘dir’ inserted into target name, the pack size increased much at second time, and keep almost the same afterwards :
[planet@planetCentOS01 tar_bug_test]$ rm ggyy/d*

[planet@planetCentOS01 tar_bug_test]$ ll ggyy
total 1312
-rw-r--r--. 1 planet planet 670293 Feb 14 22:09 services
-rw-rw-r--. 1 planet planet 670293 Feb 14 23:41 services_reverse

[planet@planetCentOS01 tar_bug_test]$ **tar -zcvf ggyy/dir.tar.gz ggyy/**
ggyy/
ggyy/services
ggyy/services_reverse
tar: ggyy: file changed as we read it

[planet@planetCentOS01 tar_bug_test]$ ll ggyy
total 1576
**-rw-rw-r--. 1 planet planet 269684 Feb 15 00:04 dir.tar.gz**
-rw-r--r--. 1 planet planet 670293 Feb 14 22:09 services
-rw-rw-r--. 1 planet planet 670293 Feb 14 23:41 services_reverse

[planet@planetCentOS01 tar_bug_test]$ **tar -zcvf ggyy/dir.tar.gz ggyy/**
ggyy/
ggyy/services
ggyy/dir.tar.gz
tar: ggyy/dir.tar.gz: file changed as we read it
ggyy/services_reverse

[planet@planetCentOS01 tar_bug_test]$ ll ggyy
total 1644
**-rw-rw-r--. 1 planet planet 339164 Feb 15 00:04 dir.tar.gz**
-rw-r--r--. 1 planet planet 670293 Feb 14 22:09 services
-rw-rw-r--. 1 planet planet 670293 Feb 14 23:41 services_reverse

[planet@planetCentOS01 tar_bug_test]$ **tar -zcvf ggyy/dir.tar.gz ggyy/**
ggyy/
ggyy/services
ggyy/dir.tar.gz
tar: ggyy/dir.tar.gz: file changed as we read it
ggyy/services_reverse

[planet@planetCentOS01 tar_bug_test]$ ll ggyy
total 1644
**-rw-rw-r--. 1 planet planet 339163 Feb 15 00:04 dir.tar.gz**
-rw-r--r--. 1 planet planet 670293 Feb 14 22:09 services
-rw-rw-r--. 1 planet planet 670293 Feb 14 23:41 services_reverse

[planet@planetCentOS01 tar_bug_test]$ tree
.
`-- ggyy
    |-- dir.tar.gz
    |-- services
    `-- services_reverse

1 directory, 3 files


  1. Here shows the OS version and “tar” version:
[planet@planetCentOS01 tar_bug_test]$ uname -a
Linux planetCentOS01 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

[planet@planetCentOS01 tar_bug_test]$ tar --version
tar (GNU tar) 1.26
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.

What I tried:
I just tried these operations, one including the word “dir”, and one not including.
I were very confused at this strange when practicing “tar”. I casually used the word “dir” and made this bug. After I tried other word, I found it goes wrong only with “dir” included such as “exdirdsa.tar.gz”, “uudir.tar.gz”, “diraa.tar.gz”).

Expectation:
No expectation just a report. Anybody curious can try to troubleshoot. These bugs are so rare and so difficult to meet that will not cause trouble in normal uses.

Read more here: Source link