You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gh-88661: Derive the gzip FNAME field like gunzip does
The FNAME field of the gzip header is meant to hold the name the file is
expected to have after decompression, but gzip and tarfile only stripped
a literal ".gz" suffix. An archive created as "spam.tgz" therefore
recorded "spam.tgz", so decompressors that honor FNAME wrote out a tar
file still named ".tgz".
Match gunzip instead: compare the suffix ignoring case, and replace
".tgz" and ".taz" with ".tar" rather than leaving them in place. This
covers both code paths, GzipFile._write_gzip_header (mode "w:gz") and
tarfile._Stream._init_write_gz (mode "w|gz").
Only the suffix is matched ignoring case; the rest of the name keeps the
case it was given. gunzip behaves the same way: get_suffix() lowercases
only the trailing bytes it compares, and make_ofname() calls strlwr() on
the suffix alone, so "SPAM.TGZ" becomes "SPAM.tar". Both branches are
tested with an upper-case stem.
Deliberately left out, being separate user-visible changes rather than
part of deriving the FNAME field: the remaining suffixes gunzip knows
(".z", "-gz", "-z" and "_z"), and the "python -m gzip -d" CLI, which
still accepts only a literal ".gz" argument. ".tz" is not added because
it is not a gunzip suffix at all, unlike ".taz".
0 commit comments