pkg/oci: update TestOpenUserFileCapsReads to use newlined data

This test verifies the maximum file-size constraints that were added in
[containerd7b05ec4]. However, github.com/moby/sys@v0.4.1 adds similar
constraints, including a constraint on line-length (1M): [moby/sys@2c56c3d]
that may hit before the file-size limit is reached if the data does not
contain newlines.

This patch updates the test to use data that includes newlines to make
sure it's testing the file-size constraints, not line-limit constraints.

[containerd7b05ec4]: 7b05ec421d
[moby/sys@2c56c3d]: 2c56c3d5d0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2026-06-26 09:40:21 +02:00
parent 152f44b969
commit 7a7aebfcbf

View File

@@ -30,6 +30,8 @@ import (
// TestOpenUserFileCapsReads asserts the boundary behavior of the read cap:
// well below, ending exactly at, and past maxUserFileBytes.
//
// Regression test for CVE-2026-47262 / GHSA-jpcc-p29g-p8mq
func TestOpenUserFileCapsReads(t *testing.T) {
t.Parallel()
@@ -60,7 +62,13 @@ func TestOpenUserFileCapsReads(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
data := append(bytes.Repeat([]byte{0}, tc.padBytes), beyond...)
pattern := []byte("# padding\n")
pad := bytes.Repeat(pattern, (tc.padBytes+len(pattern)-1)/len(pattern))[:tc.padBytes]
if len(pad) > 0 {
pad[len(pad)-1] = '\n'
}
data := append(pad, beyond...)
fsys := fstest.MapFS{
"etc/group": &fstest.MapFile{Data: data, Mode: 0o644},
}