Commit Graph

12 Commits

Author SHA1 Message Date
Miloslav Trmač 8ce59962c9 Add unit tests to ensure manifest Clone doesn't lose data
No non-test code changes, should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-07-01 19:39:55 +02:00
Miloslav Trmač 942cb5c134 Reject unsupported encryption/decryption updates in UpdateLayerInfos
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-09-06 20:08:32 +02:00
Miloslav Trmač 8ba8048183 Convert tests for UpdateLayerInfos to table-driven
... to cut down on the repetitiveness.

Should not change (test) behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-09-06 20:08:32 +02: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č 83aee8f797 Reject OCI artifacts in manifest.OCI1.ImageID
... and add tests for the ImageID implementations.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-16 20:38:15 +02:00
Miloslav Trmač 38b1d742f3 Simplify repetitive code in manifest tests
Add manifestSchema2FromFixture and manifestOCI1FromFixture
instead of open-coding the read+decode steps over and over.

The tests also fail immediately if they can't use the
fixture, instead of somehow trying to continue (and probably
crashing).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-16 20:38:15 +02:00
Miloslav Trmač ef4d0e22ef Reformat TestSupported*MediaType
Having each test case streched across four lines doesn't
make it any more readable; seeing the test cases on the
same screen as the test body is more valuable.

Should not change (test) behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-16 20:38:15 +02:00
Miloslav Trmač 7152f888b9 Update users of deprecated io/ioutil
Mostly just name changes that should not change behavior,
apart from ioutil.ReadDir -> os.ReadDir avoiding per-item
lstat(2) in some cases.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-04-13 20:46:48 +02: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č 7d9cde7252 Update to major version v5
> gomove github.com/containers/image/v4 github.com/containers/image/v5
+ a manual edit of go.mod

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-10-25 22:27:45 +02:00
Miloslav Trmač e568c94ef3 Correctly use a c/image/v4 module namespace
... so that major-version-aware Go module import
(as opposed to vX.Y.Z+incompatible, which does not allow different
packages to use different versions) works right.

Also requires adding some more GO111MODULE=on options to Makefile.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-10-03 22:54:27 +02:00
Valentin Rothberg 69aa1e8546 media type checks
When copying an image, record the compression in the BlobInfo and use
the information when updating the manifest's layer infos to set the
layers' media types correctly.

Also check for supported media types when parsing a v2s2/OCI1 manifest.

Note that consumers of the containers/image library need to update
opencontainers/image-spec to commit 775207bd45b6cb8153ce218cc59351799217451f.

Fixes: github.com/containers/libpod/issues/2013
Fixes: github.com/containers/buildah/issues/1589

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-09-09 12:20:20 +02:00