zukomp bundles third-party source code under src/vendor/. Provenance for every
bundled source -- upstream repository, release tag, commit, archive checksum,
license and the local patches applied -- is recorded in
tools/vendor/manifest.tsv and can be re-verified offline with
tools/vendor/verify.

-------------------------------------------------------------------------------
miniz (src/vendor/miniz/)
-------------------------------------------------------------------------------

Upstream:  https://github.com/richgel999/miniz
Release:   3.1.2 (commit 77d0dce8627735138c51770d1799a1ef48f2117d)
License:   MIT. The notice is reproduced verbatim in
           src/vendor/miniz/LICENSE in the source package, and is installed
           as <zukomp>/licenses/miniz-LICENSE -- miniz.h carries no copyright
           line or permission notice of its own, and an installed zukomp
           ships both that header and compiled miniz code (see below).

  Copyright 2013-2014 RAD Game Tools and Valve Software
  Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
  Copyright 2016 Martin Raiber

Authorship credited in the bundled sources, beyond the copyright lines above:

  Rich Geldreich     author of miniz.
  Martin Raiber      ZIP archive code (copyright line in miniz.c's ZIP
                     section, under the same MIT terms).
  Alex Evans         original PNG writer, tdefl_write_image_to_png_file_in_
                     memory_ex(), released by him into the public domain
                     and modified upstream. Compiled out of both builds.
  Alistair Moffat,   tdefl_calculate_minimum_redundancy(), the in-place
  Jyrki Katajainen   minimum-redundancy code-length computation (1996).

All of the above are listed in Authors@R in DESCRIPTION, with 'ctb' and,
where they hold copyright, 'cph' roles.

The bundled copy is compiled twice, from the same sources, with two different
sets of MINIZ_NO_* flags (see src/Makevars):

  zukomp.so             the codecs. The ZIP reader and writer, the PNG
                        writer, all file I/O and all clock access are
                        compiled out, and miniz's zlib-compatible names are
                        disabled so nothing collides with the zlib R links.

  libzukomp.a           the LinkingTo surface, for a consumer that has to
                        read a ZIP container. Same sources and same patches,
                        with the ZIP reader, stdio and timestamps left in.
                        The ZIP writer stays compiled out.

An installed zukomp therefore contains third-party code in three places:
compiled into <zukomp>/libs/, compiled into <zukomp>/lib/ as libzukomp.a,
and as the patched header <zukomp>/include/miniz.h. miniz's licence is
installed at <zukomp>/licenses/miniz-LICENSE, covering all three.

Both compilations carry the same six local patches, all under
tools/patches/miniz/:

  0001-guard-png-writer.patch        puts the PNG writer behind
                                     MINIZ_NO_PNG_APIS, which upstream does
                                     not provide.

  0002-validate-match-distance.patch rejects a DEFLATE match distance that
                                     reaches back further than the bytes
                                     emitted so far, as RFC 1951 section
                                     3.2.5 requires. Upstream performs this
                                     check only when decompressing into a
                                     non-wrapping output buffer, which a
                                     streaming caller never uses. The count
                                     of bytes emitted saturates at the
                                     window, so it cannot wrap where size_t
                                     is 32 bits.

  0003-guard-mz-assert.patch         wraps the MZ_ASSERT definition in
                                     #ifndef and adds MINIZ_NO_ASSERT, so an
                                     embedder can override it. Upstream
                                     defines it unconditionally, leaving its
                                     behaviour to NDEBUG alone.

  0004-reject-missing-end-of-block.patch
                                     rejects a dynamic DEFLATE block whose
                                     literal/length table gives the
                                     end-of-block symbol no code, as RFC 1951
                                     section 3.2.5 implies and zlib does.
                                     Upstream decodes such a block's
                                     literals instead.

  0005-zip-reader-hostile-input.patch makes the ZIP reader refuse, with an
                                     error code, four hostile archives it
                                     accepted or hung on: a truncated
                                     member read from memory through the
                                     extraction iterator (a hang), a stored
                                     entry whose sizes differ, a DEFLATE
                                     failure reported with no error code,
                                     and an empty entry whose CRC-32 or
                                     ZIP64 size is not empty. It also finds
                                     the central directory behind a long
                                     archive comment. It changes
                                     only the ZIP reader, so only
                                     libzukomp.a is affected.

  0006-reject-reserved-codes.patch
                                     rejects the codes RFC 1951 reserves:
                                     literal/length symbols 286 and 287 and
                                     distance symbols 30 and 31, which the
                                     fixed code still codes, and dynamic
                                     tables that declare more than 286 or 30
                                     codes. Upstream decodes a reserved
                                     symbol as an empty match or distance 0
                                     and accepts such tables; zlib refuses
                                     all of them.

All six are written to be upstreamable unchanged. No other modification is
made to upstream sources.

-------------------------------------------------------------------------------
Zstandard (src/vendor/zstd/)
-------------------------------------------------------------------------------

Upstream:  https://github.com/facebook/zstd
Release:   v1.5.7 (commit f8745da6ff1ad1e7bab384bd1f9d742439278e99)
License:   BSD 3-Clause. Upstream offers zstd under BSD-3-Clause or GPLv2 at
           the recipient's choice; zukomp takes and redistributes it under
           BSD-3-Clause only. The notice is reproduced verbatim in
           src/vendor/zstd/LICENSE.

  Copyright (c) Meta Platforms, Inc. and affiliates.
  Copyright (c) Yann Collet - Meta Platforms, Inc (xxHash, bundled in
                common/xxhash.h)
  Copyright (c) 2016 Tino Reichardt (common/threading.c, threading.h;
                compiled single-threaded here, so those files reduce to
                stubs)

Included: lib/zstd.h, lib/zstd_errors.h and lib/common/, lib/compress/ and
lib/decompress/, less decompress/huf_decompress_amd64.S. Not included:
dictBuilder/, legacy/, deprecated/, dll/, zdict.h and the command-line
programs. Compiled with ZSTD_DISABLE_ASM=1, ZSTD_LEGACY_SUPPORT=0 and
XXH_NAMESPACE=ZSTD_, and with its public functions' explicit default
visibility removed so that zukomp.so exports none of them.

Four local patches, under tools/patches/zstd/:

  0001-drop-clang-diagnostic-pragma.patch
                                     removes a "#pragma clang diagnostic
                                     ignored" around ZSTD_defaultCMem in
                                     zstd.h. It suppresses a C++-only
                                     warning, zukomp compiles zstd as C, and
                                     R CMD check reports such pragmas. No
                                     code changes.

  0002-check-content-size-after-empty-last-block.patch
                                     makes the streaming decoder check a
                                     frame's declared content size when the
                                     frame ends in an empty last block, as
                                     it already does after a non-empty one
                                     and as the one-shot decoder always
                                     does. Upstream accepted such a frame
                                     whatever it had decoded.

  0003-check-rle-block-size-not-body.patch
                                     makes the streaming decoder compare an
                                     RLE block's regenerated size with the
                                     frame's maximum block size, as RFC 8878
                                     defines it, rather than the block's
                                     one-byte body. Upstream refused a valid
                                     RLE block of size 0 in a frame whose
                                     maximum is 0.

  0004-refuse-empty-compressed-block.patch
                                     makes the streaming decoder refuse a
                                     compressed block of size 0, as the
                                     one-shot decoder does. Upstream took it
                                     for an empty block and went on.

-------------------------------------------------------------------------------
LZ4 (src/vendor/lz4/)
-------------------------------------------------------------------------------

Upstream:  https://github.com/lz4/lz4
Release:   v1.10.0 (commit ebb370ca83af193212df4dcbadcc5d87bc0de2f0)
License:   BSD 2-Clause, the licence of the LZ4 library (lib/); the GPLv2
           that covers lz4's command-line programs does not apply, as no
           program is included. The notice is reproduced verbatim in
           src/vendor/lz4/LICENSE.

  Copyright (C) 2011-2023, Yann Collet.

Included: lz4.c, lz4.h, lz4frame.c, lz4frame.h, lz4hc.c, lz4hc.h, xxhash.c
and xxhash.h from lib/. Not included: lz4file.c, lz4frame_static.h, the dll
files and the programs. Compiled with XXH_NAMESPACE=LZ4_ and NDEBUG, and
with its public functions' explicit default visibility removed so that
zukomp.so exports none of them.

One local patch, under tools/patches/lz4/:

  0001-drop-unused-function-pragmas.patch
                                     removes two "#pragma ... diagnostic
                                     ignored -Wunused-function" lines from
                                     lz4hc.c, which R CMD check reports. No
                                     code changes.

Yann Collet, Meta Platforms, Inc. and affiliates, and Tino Reichardt are
listed in Authors@R in DESCRIPTION, with 'cph' roles and, for the two people,
'ctb'. LICENSE.note at the top of the source package summarises all three
bundled licences.

No other modification is made to the zstd or lz4 sources. Unlike miniz,
neither library's headers are installed and neither is part of
libzukomp.a: both exist only compiled into <zukomp>/libs/, and their
licences are installed as <zukomp>/licenses/zstd-LICENSE and
<zukomp>/licenses/lz4-LICENSE.
