Commit Graph

17 Commits

Author SHA1 Message Date
Miloslav Trmač cebe64776a Quote various strings coming from untrusted sources
Typically, use %q instead of %s (or instead of "%s"), to expose
various control characters and the like without interpreting them.

This is not really comprehensive; the codebase makes no _general_
guarantee that any returned string values are free of control
characters or other malicious/misleading metadata. Not even
in returned "error" values (which can legitimately contain newlines,
if nothing else).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-05-09 19:22:23 +02:00
Miloslav Trmač 1b8ab79b21 Document InternalUnstableUndocumentedMIMEQuestionMark as BaseVariantName
Commit to it as a public API; it's really only usable for
.BaseVariantName() == .Name().

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-02-28 16:41:31 +01:00
Aditya R 8a1955ba80
manifest: introduce internal/manifest.ListInternal and freeze manifest.List
Flips dependency of internal and public manifest.List API and introduces
private manifest.List API which will be extended in future for new
features.

[NO NEW TESTS NEEDED]
[NO TESTS NEEDED]

Signed-off-by: Aditya R <arajan@redhat.com>
2023-02-08 11:21:46 +05:30
Miloslav Trmač 24359e09d1 s/interface{}/any/g
... in almost all cases.

Also rename mSI (map[string]interface{}) to mSA (map[string]any).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-03 18:34:11 +01:00
Miloslav Trmač 23a22f1f93 Use golang.org/x/exp to avoid open-coded loops.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-03 18:33:34 +01:00
ningmingxiao a576137520 enhance inspect
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
2022-08-09 13:01:48 +08:00
Miloslav Trmač 6d458ba211 Introduce SourcedImage.CanChangeLayerCompression, use it in copy.Image
- Don't compress/decompress layers with unknown MIME types, and layers
  in OCI artifacts.
- Don't even change manifest MIME types in these situations, whatever
  happens.
- Don't substitute compressed/uncompressed variants (via
  TryReusingBlobWithOptions) for OCI artifacts, if we discover the
  same variants when copying images that refer to the same blobs.

Note that this does _not_ restrict compression to algorithms supported
by the SourcedImage, because that would prohibit a single-pass
conversion from v2s2 to OCI while compressing to zstd [1], and that's
a feature we currently exercise in tests. So, this prevents us from
failing to copy OCI artifacts, but users of zstd still need to be careful
about choosing OCI manually.

[1] We would need to ask the _destination_ format handler about
zstd, not the source-format SourcedImage, and we don't currently have
that infrastructure. It's also not immediately clear how to combine
this with the sequence of alternative manifest formats returned by
determineManifestConversion.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-16 20:38:15 +02:00
Miloslav Trmač af70b53bbc Split findCompressionMIMETypeSet from compressionVariantMIMEType
We will add another user of the lookup code.

Erorr messages now use mimeType instead of mt, which were required
required to be equal on that code path, now that mt is not visible.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-16 20:38:15 +02:00
Daniel J Walsh 968e9a510b
Run codespell on code
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-01-21 07:57:07 -05:00
Miloslav Trmač 7bcf9bc8b6 Reject ambiguous manifest formats
Refuse to process manifest / manifest list data
that could possibly be interpreted as two different
manifest formats, because differences in how those
ambiguities are resolved could be used to bypass
image verification or review mechanisms.

Fixes CVE-2021-41190 / GHSA-77vh-xpmg-72qh .

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-11-17 21:43:59 +01:00
Miloslav Trmač 3c376ba255 Use pkg/compression/types where possible
Most importantly this removes a dependency of c/image/manifest
(and thus c/image/signature) on pkg/compression and all the implementations.

Use pkg/compression/types everywhere else it is possible as well,
even if it does not remove any dependency on pkg/compression, just
to enforce the discipline.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-07-26 15:08:20 +02:00
Miloslav Trmač bf12b61ef5 Rename compression.Algorithm.MIME
... to InternalUnstableUndocumentedMIMEQuestionMark , as
a minimal low-effort attempt to prevent this being a part
of the API stability promise.

Hopefully this will actually be properly documented, or replaced
with something maintainable, instead; this is a stupid stopgap
to decrease the risk of the current state becoming a part of a release.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-07-09 12:58:34 +02:00
Giuseppe Scrivano 7421a48994
compression: let algorithms register a MIME type
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-07-02 14:36:48 +02:00
Nalin Dahyabhai 5364600209 blobinfocache: track compression types for locations
Extend the blob info cache to also cache the name of the type of
compression used on a blob that we've seen, or specific values that
indicate that we know the blob was not compressed, or that we don't
know whether or not it was compressed.

New methods for adding known blob-compression pairs and reading
candidate locations including compression information are part of a new
internal BlobInfoCache2 interface which the library's BlobInfoCache
implementors also implement.

When we copy a blob, try to record the state of compression for the
source blob, and if we applied any changes, the blob we produced.

Make sure that when TryReusingBlob successfully uses a blob from the
blob info cache, that it provides compression information in the
BlobInfo that it returns, so that manifests can be updated to describe
layers using the correct MIME types.

When attempting to write a manifest, if a manifest can't be written
because layers were compressed using an algorithm which can't be
expressed using that manifest type, continue on to trying other manifest
formats.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-01-16 13:58:15 -05:00
Miloslav Trmač d459ef043a Factor out updatedMIMEType out of updatedSchema2MIMEType / updatedOCI1MIMEType
Apart from the variant table name, and the MIME type check in schema2,
the two are line-for-line identical.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-04-27 21:50:51 +02:00
Miloslav Trmač c5509767e1 Make MIME type conversions table-driven
... instead of doing exactly the same linear lookups in
manually-written code.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-04-27 21:47:19 +02:00
Miloslav Trmač 7a731fdd75 Move format-indepenent private utilities to manifest/common.go
separate from the format-specific files, and from the ~generic
public utilities in manifest.go.

Only moves code, should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-04-27 21:34:14 +02:00