Files
Sebastiaan van Stijn 90bfd2f47b util/contentutil: remove uses of "-1" sentinel value for sizes
The [content.Copy] helper in containerd accepted both `0` and `-1` (or
technically: "any negative value") as sentinel value for content with an
unknown size. While both worked, the function itself only documented
"empty" (`0`) as acccepted values.

Containerd 2.4.2, 2.3.7, 2.2.10, and 2.0.14 applied additional constraints
to prevent a malicious "Size" header from resulting in an unbounded write
(GHSA-hc94-p972-ch66).

As part of the mitigation, the Copy utility now also rejected negative
values ([containerd@91f62bd]) including the (undocumented) `-1` sentinel
value.

While the previous behavior may be restored in a future release of containerd,
let's already remove uses of this undocumented feature in BuildKit.

It's worth noting that the behavior of [content.WriteBlob] also changed due
to the same changes. Behavior of this helper will not be restored, as an
OCI Descriptor with a negative size is not accepted.

[OCI Image Spec v1.1.1] describes it as

> If the length of the retrieved content does not match the specified
> length, the content SHOULD NOT be trusted.

A later commit ([image-spec@02ba6e2]) strengthens this requirement,
adding;

> The size MUST NOT be negative.

[containerd@91f62bd]: https://github.com/containerd/containerd/commit/91f62bdd77e8851fbc6153013b52c25d2badf80e
[content.Copy]: https://github.com/containerd/containerd/blob/v2.4.1/core/content/helpers.go#L184-L191
[content.WriteBlob]: https://github.com/containerd/containerd/blob/v2.4.1/core/content/helpers.go#L126-L133
[image-spec@02ba6e2]: https://github.com/opencontainers/image-spec/commit/02ba6e2143771aaefdb542c2222f40db48ef3a0b

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit b143318e6e)
2026-11-03 10:58:13 +01:00
..
2026-08-26 02:06:18 -07:00
2018-01-31 18:44:09 -08:00
2025-05-02 12:44:01 -07:00
2026-01-13 22:09:25 -08:00
2025-01-13 16:42:48 -08:00
2024-09-26 12:57:45 -05:00
2026-08-16 23:09:01 +02:00
2026-08-16 23:09:01 +02:00
2026-08-26 02:06:18 -07:00
2026-05-14 10:13:21 -07:00
2024-06-10 21:16:51 -07:00