History log of /freebsd-current/usr.bin/gzip/gzip.c
Revision Date Author Comments
# 0b8224d1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

Remove copyright strings ifdef'd out

We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# b61a5730 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-NetBSD identifier is obsolete, drop -NetBSD

The SPDX folks have obsoleted the BSD-2-Clause-NetBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# f9349d42 02-Nov-2022 Dag-Erling Smørgrav <des@FreeBSD.org>

gzip: Add support for decompressing zstd files.

Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D37236


# 4669f23e 27-Jan-2022 Tom Jones <thj@FreeBSD.org>

Remove SMALL conditionals from gzip

gzip has SMALL conditionals which enable building a reduced size version
of the binary. These exist as part of the introduction of BSD licensed
gzip in 2004 in NetBSD and appear to have been required to reach a size
for inclusion in their install media. For more information see commits
to gzip in the NetBSD tree on the 28th of March 2004.

SMALL doesn't appear to be hooked up to our build system and
complicates gzip quite a bit.

Reviewed by: kevans, imp
Sponsored by: Klara Inc.
Differential Revision: https://reviews.freebsd.org/D34047


# 21c966a6 27-Jan-2022 Tom Jones <thj@FreeBSD.org>

Fix test output when gzip is run with -tlv

When run with test, verbose and list we need to parse the file otherwise
the test output is "NOT OK" even for the file is valid.

Reviewed by: kevans, allanjude, imp
Sponsored by: Klara Inc.
Differential Revision: https://reviews.freebsd.org/D34046


# 2dfa4b66 08-Dec-2020 Bryan Drewery <bdrewery@FreeBSD.org>

fts_read: Handle error from a NULL return better.

This is addressing cases such as fts_read(3) encountering an [EIO]
from fchdir(2) when FTS_NOCHDIR is not set. That would otherwise be
seen as a successful traversal in some of these cases while silently
discarding expected work.

As noted in r264201, fts_read() does not set errno to 0 on a successful
EOF so it needs to be set before calling it. Otherwise we might see
a random error from one of the iterations.

gzip is ignoring most errors and could be improved separately.

Reviewed by: vangyzen
Sponsored by: Dell EMC
Differential Revision: https://reviews.freebsd.org/D27184


# a0eb385c 13-Mar-2020 Xin LI <delphij@FreeBSD.org>

Remove unneeded checks for prelen.

In order to determine the type of a compressed file, we have to read
in the first four bytes which may also be important for decompression
purposes, to do that we would pass the buffer that we have already
read in, along with the size of it.

Rename header1 to fourbytes to make that explicit, and remove all
checks for prelen.

Reported by: cem
Reviewed by: cem
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D24034


# 5c4b64e6 07-Jan-2019 Xin LI <delphij@FreeBSD.org>

Port NetBSD improvements:

- Add -l support for xz files
- Add lzip support to gzip based on the example lzip decoder.

Obtained from: NetBSD
MFC after: 2 weeks
Relnotes: yes


# 34e314e7 09-Jul-2018 Xin LI <delphij@FreeBSD.org>

Use endian.h le32dec() instead of rolling our own.

Suggested by: phk
Reviewed by: imp, pfg
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D16192


# e76247cd 09-Jul-2018 Conrad Meyer <cem@FreeBSD.org>

gzip(1): Don't shadow global 'err'

Unbreak work build on ppc due to -Werror=shadow. Introduced in r336121.

X-MFC-With: r336121


# b393a8ac 09-Jul-2018 Xin LI <delphij@FreeBSD.org>

Don't delete outfile unconditionally.

MFC after: 1 month


# 3fcbc83d 08-Jul-2018 Pedro F. Giffuni <pfg@FreeBSD.org>

gzip: fix for undefined behavior.

Unportable left shift reported with MKSANITIZER=yes
USE_SANITIZER=undefined:

# progress -zf ./games.tgz tar -xp -C "./" -f -
/public/src.git/usr.bin/gzip/gzip.c:2126:33: runtime error: left shift of
251 by 24 places cannot be represented in type 'int'
100%
|****************************************************************************************************************|
44500 KiB 119.69 MiB/s 00:00 ETA

Refactor the following code into something that is more clear
and fix signed integer shift, by casting all buf[] elements to
(unsigned int):

unsigned char buf[8];
uint32_t usize;
[...]
else {
usize = buf[4] | buf[5] << 8 |
buf[6] << 16 | buf[7] << 24;
[...]

New version:

usize = buf[4];
usize |= (unsigned int)buf[5] << 8;
usize |= (unsigned int)buf[6] << 16;
usize |= (unsigned int)buf[7] << 24;

Only the "<< 24" part needs explicit cast, but for consistency make the
integer promotion explicit and clear to a code reader.

Sponsored by <The NetBSD Foundation>

Obtained from: NetBSD (CVS rev. 1.113)
MFC after: 1 week


# f5e46072 11-Dec-2017 Xin LI <delphij@FreeBSD.org>

Close the correct file descriptor.

MFC after: 2 weeks


# 611ecc62 11-Dec-2017 Conrad Meyer <cem@FreeBSD.org>

gzip(1): Remove duplicate close()

CID: 1383560
Reported by: Coverity
Sponsored by: Dell EMC Isilon


# 1de7b4b8 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

various: general adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

No functional change intended.


# 90f528e8 21-Nov-2017 Xin LI <delphij@FreeBSD.org>

Support SIGINFO.

Obtained from: NetBSD
MFC after: 2 weeks


# 1c324569 06-Jan-2017 Konstantin Belousov <kib@FreeBSD.org>

Use type-independent formats for printing nlink_t and ino_t.

Extracted from: ino64 work by gleb, mckusick
Discussed with: mckusick
Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# 64093e14 26-Aug-2016 Xin LI <delphij@FreeBSD.org>

Use printable ASCII instead of octal representation.

MFC after: 2 weeks


# d61c7fc0 30-Jul-2016 Marcelo Araujo <araujo@FreeBSD.org>

Use nitems() from sys/param.h.

MFC after: 2 weeks.
Sponsored by: gandi.net (BSD Day Taiwan)


# 199c4466 27-Oct-2015 Xin LI <delphij@FreeBSD.org>

Update NetBSD RCS IDs to reflect the changes being upstreamed.

MFC after: 13 days
X-MFC-With: r290024


# 354ed042 26-Oct-2015 Xin LI <delphij@FreeBSD.org>

In gunzip(1), treat trailing garbage as a warning and not an error. This
allows scripts to distinguish it between real fatal errors, for instance a
CRC mismatch.

Update manual page for the behavior change.

PR: bin/203873
Submitted by: Eugene Grosbein <eugen grosbein net>
MFC after: 2 weeks


# dec32474 16-Apr-2015 Xin LI <delphij@FreeBSD.org>

r281540 was upstreamed as NetBSD r1.108 of gzip.c, note it as merged.


# c1c4677a 14-Apr-2015 Xin LI <delphij@FreeBSD.org>

When reading in the original file name from gzip header, we read
in PATH_MAX + 1 bytes from the file. In r281500, strrchr() is
used to strip possible path portion of the file name to mitigate
a possible attack. Unfortunately, strrchr() expects a buffer
that is NUL-terminated, and since we are processing potentially
untrusted data, we can not assert that be always true.

Solve this by reading in one less byte (now PATH_MAX) and
explicitly terminate the buffer after the read size with NUL.

Reported by: Coverity
CID: 1264915
X-MFC-with: 281500
MFC after: 13 days


# 0eeac589 13-Apr-2015 Xin LI <delphij@FreeBSD.org>

Sync with NetBSD:

- Mention xz(1) in gzip(1).
- Strip away path from header name when decompressing.

MFC after: 2 weeks


# d6b3ef63 17-Feb-2015 Jilles Tjoelker <jilles@FreeBSD.org>

compress,gzip,xz: Preserve timestamps with nanosecond precision.


# 060ea80e 22-Oct-2014 Xin LI <delphij@FreeBSD.org>

Sync with NetBSD.

MFC after: 2 weeks


# 140c037a 10-Oct-2011 Xin LI <delphij@FreeBSD.org>

Incorporate recent changes from NetBSD. Most notable change is the addition
of support of decompressing xz files.

Obtained from: NetBSD


# 5106ce89 25-May-2011 Xin LI <delphij@FreeBSD.org>

Fix a regression introduced with previous changeset: if output is stdout,
do not check for symbolic link.


# fc268910 23-May-2011 Xin LI <delphij@FreeBSD.org>

Match symbolic link handling behavior with GNU gzip, bzip2 and xz:

When we are operating on a symbolic link pointing to an existing
file, bail out by default, but go ahead if -f is specified.

Submitted by: arundel
MFC after: 2 weeks


# be07528c 23-May-2011 Xin LI <delphij@FreeBSD.org>

Diff reduction against NetBSD. The most notable change is to zdiff(1) to
handle more file formats including bzip2 and xz.

MFC after: 2 weeks


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# c4fadc2b 16-Oct-2010 Benedict Reuschling <bcr@FreeBSD.org>

Correct some typos in comments, no functional changes.


# fb2924e4 22-Sep-2010 Xin LI <delphij@FreeBSD.org>

In the past gunzip(1) write()'s after each inflate return. This is
not optimal from a performance standpoint since the write buffer is
not necessarily be filled up when the inflate rountine reached the
end of input buffer and it's not the end of file.

This problem gets uncovered by trying to pipe gunzip -c output to
a GEOM device directly, which enforces the writes be multiple of
sector size.

Sponsored by: iXsystems, Inc.
Reported by: jpaetzel
MFC after: 2 weeks


# a5916c2b 11-Jun-2010 Xin LI <delphij@FreeBSD.org>

MFC r208888,208889,209017:

- make sure that initialize isb with fstat() on
input file before using it. (bin/147275)
- Fix grammar for st_nlink.
- Style changes.

PR: bin/147275
Approved by: re (kensmith)


# 08b300a1 10-Jun-2010 Xin LI <delphij@FreeBSD.org>

Several style fixes as prompted by bde@.

While I'm there, loosen the st_nlink check and fix grammar for 1 extra
links.


# 1371ad15 07-Jun-2010 Xin LI <delphij@FreeBSD.org>

Follow up revision 208888 with purely ident changes.

MFC after: 1 week


# 09e979e9 07-Jun-2010 Xin LI <delphij@FreeBSD.org>

Correct a bug in gzip(1): make sure that initialize isb with fstat() on
input file before using it.

PR: bin/147275
Submitted by: thomas
MFC after: 1 week


# 50669a65 09-May-2010 Xin LI <delphij@FreeBSD.org>

MFC r207247,r207283,207284:

- Add a signal handler for SIGINT which removes output file when necessary.
- While I'm there, move unlink_input() slightly down to after closing the
output file, in uncompression path.
- Language improvements to make the BUGS section easier to read.


# 637bfa48 27-Apr-2010 Xin LI <delphij@FreeBSD.org>

Use _exit(2) system call directly instead of using exit(3) in signal
handler, as the latter is not guaranteed to be signal safe, and we
do not really care about flushing the stream during SIGINT.

Suggested by: Maxim Konovalov <maxim.konovalov gmail com>
MFC after: 13 days


# 18333f54 26-Apr-2010 Xin LI <delphij@FreeBSD.org>

Add a signal handler for SIGINT which removes output file when necessary.

While I'm there, move unlink_input() slightly down to after closing the
output file, in uncompression path.

MFC after: 2 weeks


# a9de89ae 20-Apr-2010 Xin LI <delphij@FreeBSD.org>

MFC r206387:

Diff reduction against NetBSD and add myself to AUTHORS section of the
manual page as I wrote the unpack functionality. No actual executable
code change verified with md5(1).


# feeb03b2 07-Apr-2010 Xin LI <delphij@FreeBSD.org>

Diff reduction against NetBSD and add myself to AUTHORS section of the
manual page as I wrote the unpack functionality. No actual executable
code change verified with md5(1).


# 99742a23 28-Mar-2010 Ed Schouten <ed@FreeBSD.org>

Change all our own code to use st_*tim instead of st_*timespec.

Also remove some local patches to diff(1) which are now unneeded.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# deb63277 31-Jul-2009 Xin LI <delphij@FreeBSD.org>

Correct a stack underflow in gzip:

- Limit suffix to be no more than 30 bytes long. This matches GNU
behavior.
- Correct usage of memcpy().

Note that this commit only corrects the stack underflow issue, we
still need some other fixes to cover other edges. [1]

Reported by: Ron Jude <ronj wytheville org>
Discussed with: Matthew Green (original NetBSD gzip author),
Eygene Ryabinkin <rea-fbsd codelabs ru> [1]
Approved by: re (kib)


# b47ed83d 24-Jun-2009 Xin LI <delphij@FreeBSD.org>

Sync with NetBSD:
- gzip -n does not store timestamp; [1]
- Reduce diff against NetBSD by moving some casts in our local
versions.

PR: bin/134955
Obtained from: NetBSD
MFC after: 1 month


# 4ca8a62b 21-Jun-2009 Xin LI <delphij@FreeBSD.org>

Add support for uncompressing pack(1)'ed files. Pack(1) is a program found
in some commercial Unix systems, which utilizes Huffman minimum redundancy
code tree to compress files. This implementation supports the "new" pack
format only, just like GNU gzip did.

Thanks for oliver@'s archive set which I can test against, and Mingyan Guo
for providing helpful review of my code.

PR: bin/109567
MFC after: 1 month


# 80b807fe 19-Jun-2009 Xin LI <delphij@FreeBSD.org>

Two fixes for SMALL case when compiling with WARNS=6:

- Reduce scope where return value can be referenced.
- Add a dummy access to timestamp to silence warning.

Submitted by: Mingyan Guo <guomingyan gmail com>


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 80d61a6a 04-Aug-2008 Colin Percival <cperciva@FreeBSD.org>

Mark functions as __dead2 in order to help the LLVM static checker
understand which code paths aren't possible.

Reported by: edwin


# bf156626 22-Jul-2008 Xin LI <delphij@FreeBSD.org>

Sync with NetBSD's license changes.


# 3c235488 09-Mar-2008 Robert Watson <rwatson@FreeBSD.org>

Teach gunzip that .tbz and .tbz2 uncompress to .tar, in a manner similar to
its existing understanding that .tgz uncompresses to .tar.

MFC after: 3 days
PR: 121519
Submitted by: Ighighi <ighighi at gmail.com>


# c7b65254 09-Mar-2008 Robert Watson <rwatson@FreeBSD.org>

When gzipping to a target file, only set the source file flags on the
target file after the timestamp has been set; otherwise setting the
timestamp will fail if the flags don't permit it (i.e., uchg).

MFC after: 1 week
PR: 120208
Submitted by: Ighighi <ighighi at gmail.com>


# 78b8781a 11-Jul-2007 Xin LI <delphij@FreeBSD.org>

- Simulate GNU gzip(1) behavior where full filename is
being output in verbose mode when doing recursive[1].
- Use better representation of S:

PR: bin/114470
Submitted by: Ighighi <ighighi gmail com> [1]
Approved by: re (hrs)


# 2a8e7ac9 28-May-2007 Xin LI <delphij@FreeBSD.org>

Add a '-k' flag which is similar with its bzip2(1) counterpart,
meaning that the user wants the input file to be left intact.

Feature request: Ighighi <ighighi gmail.com>
PR: bin/103006
MFC after: 1 month


# 161c3dc4 31-Jan-2007 Xin LI <delphij@FreeBSD.org>

Fix typo.

Obtained from: DragonFly


# 9a9ea25f 26-Jan-2007 Xin LI <delphij@FreeBSD.org>

Replace the GNU gzip with a slightly modified NetBSD gzip. The
NetBSD version is a feature-to-feature re-implementation of GNU
gzip using the freely-redistributable zlib and this version is
expected to be mostly bug-to-bug compatible with the GNU
implementation.

- Because this is a piece of mature code and we want to make
changes so it is added directly rather than importing to
src/contrib.
- Connect newly added code to src/usr.bin/ and rescue/rescue
build.
- Disconnect the GNU gzip code from build for now, they will
be eventually removed completely.
- Provide two new src.conf(5) knobs, WITHOUT_BZIP2_SUPPORT and
WITHOUT_BZIP2.

Tested by: kris (full exp-7 pointyhat build)
Approved by: core (importing a 4-clause BSD licensed file)
Approved by: re (adding new utility during -HEAD code slush)