Mitigate archive decoder panic and harden console response headers
8 files changed,
+206
−7
docs/superpowers/reviews/REVIEW-BRIEF-security-review-mitigations.md+17 −0go.mod+7 −7go.sum+14 −0internal/console/securityheaders.go+13 −0internal/console/securityheaders_test.go+55 −0internal/console/server.go+1 −0internal/moves/archive/zstd_malformed_test.go+57 −0internal/rootfsimage/zstd_malformed_test.go+42 −0
diff --git a/docs/superpowers/reviews/REVIEW-BRIEF-security-review-mitigations.md b/docs/superpowers/reviews/REVIEW-BRIEF-security-review-mitigations.md| new file mode 100644 |
| index 000000000..5b1f83e1a |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/REVIEW-BRIEF-security-review-mitigations.md |
| @@ -0,0 +1,17 @@ |
| +# Security mitigation implementation review |
| + |
| +Repo carlos/platform, branch `security-review-mitigations`. Base: fd6d39ec471637ddb460ea7b05bb971d95c476a5 (amadan main at branch creation). Review the committed branch diff against that base and the exact tip supplied by the author. |
| + |
| +Original system audit: GLM 5.3 and Mistral Large 4, round 1, no P1; no broad audit reopened. This is the first implementation/security check for the P2 fixes, inside the stopping-rule budget. No earlier implementation findings. Maximum three rounds total; stop at the first no-P1 round, apply P2 without reopening broad review, carry P3 as follow-up. The same fault family in two rounds stops fixes and requires Paul's choice. |
| + |
| +Fixed user ruling: legacy flat tenants are Paul's trusted apps. Do not demand migration or UID redesign for those tenants. New-tenant layout policy and gVisor rollout are investigated separately; this diff does not claim to enforce that policy or deploy production changes. Static-site security headers are an unsupported product capability, tracked in discussion #771; no carloku-specific edge workaround. |
| + |
| +Review: |
| +- go.mod/go.sum update compress to v1.20.2 and x/net to v0.62.0, including only required transitive minimums. Check compatibility with platform/root paths. |
| +- Malformed zstd regression tests traverse archive Extract/Verify and rootfsimage OpenLayout. The malformed frame must actually reach the decoder: tests were watched panic on v1.18.0 and pass on v1.20.2. Inspect the framing, cleanup assertions and input validation. |
| +- Console headers before redirect/admission: CSP frame-ancestors none, object-src none, base-uri self; XFO DENY; nosniff; strict-origin-when-cross-origin; host-only HSTS max-age 86400 only for an HTTPS configured origin. No default/script-src restriction, no includeSubDomains/preload, no tenant-edge policy, no version-header removal. Check legitimate console flows and response variants, including TLS termination and plain HTTP development. Security headers must not reorder authentication, CSRF, owner or freshness gates. |
| +- Scope: production edits are console-only plus dependency versions; root consumer tests added. Check root-read census output supplied by author; every newly changed root/security/storage behavior needs this independent approval. |
| + |
| +P1: unsafe/broken, with failure scenario and verified file:line. P2: wrong/missing, fix without restarting review. P3: polish, follow-up only. Name invariant/trust boundary (fault family) per finding. Do not inflate severity to keep review open. |
| + |
| +Return ranked findings with concrete fix and checked evidence, then exactly READY (no P1/P2), READY AFTER FIXES (no P1), or NOT READY (P1). This is code review, not deployment approval. Do not edit, spawn agents, access production, or run full tests. At most 35 read/search operations. |
diff --git a/go.mod b/go.mod| index e485e3252..bf65ac4ba 100644 |
| --- a/go.mod |
| +++ b/go.mod |
| @@ -26,9 +26,9 @@ require ( |
| github.com/pion/stun/v3 v3.1.5 |
| github.com/pion/turn/v4 v4.1.4 |
| github.com/superfly/ltx v0.5.1 |
| - golang.org/x/crypto v0.57.0 |
| - golang.org/x/net v0.60.0 |
| - golang.org/x/sys v0.48.0 |
| + golang.org/x/crypto v0.58.0 |
| + golang.org/x/net v0.62.0 |
| + golang.org/x/sys v0.49.0 |
| modernc.org/sqlite v1.55.0 |
| ) |
| @@ -76,8 +76,8 @@ require ( |
| github.com/wasilibs/go-re2 v1.3.0 // indirect |
| github.com/wlynxg/anet v0.0.5 // indirect |
| golang.org/x/mod v0.41.0 // indirect |
| - golang.org/x/sync v0.23.0 // indirect |
| - golang.org/x/text v0.42.0 // indirect |
| + golang.org/x/sync v0.24.0 // indirect |
| + golang.org/x/text v0.43.0 // indirect |
| google.golang.org/protobuf v1.36.10 // indirect |
| modernc.org/libc v1.74.1 // indirect |
| modernc.org/mathutil v1.7.1 // indirect |
| @@ -88,9 +88,9 @@ require ( |
| amadan.net/carlos/platform.git/launchctx v0.0.0 |
| github.com/KarpelesLab/squashfs v1.2.0 |
| github.com/aws/aws-sdk-go-v2/service/sns v1.43.0 |
| - github.com/klauspost/compress v1.18.0 |
| + github.com/klauspost/compress v1.20.2 |
| github.com/oschwald/maxminddb-golang v1.13.1 |
| - golang.org/x/tools v0.49.0 |
| + golang.org/x/tools v0.51.0 |
| ) |
| replace amadan.net/carlos/platform.git/launchctx => ./launchctx |
diff --git a/go.sum b/go.sum| index f90cabcb9..74537b15b 100644 |
| --- a/go.sum |
| +++ b/go.sum |
| @@ -132,6 +132,8 @@ github.com/jalaali/go-jalaali v0.0.0-20210801064154-80525e88d958 h1:qxLoi6CAcXVz |
| github.com/jalaali/go-jalaali v0.0.0-20210801064154-80525e88d958/go.mod h1:Wqfu7mjUHj9WDzSSPI5KfBclTTEnLveRUFr/ujWnTgE= |
| github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= |
| github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= |
| +github.com/klauspost/compress v1.20.2 h1:v5tiZvm1KGLyg5d5oXdXe3lsSPrbEUiKoXGia//I7Qo= |
| +github.com/klauspost/compress v1.20.2/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI= |
| github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8= |
| github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= |
| github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= |
| @@ -224,25 +226,37 @@ go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6 |
| go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA= |
| golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M= |
| golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA= |
| +golang.org/x/crypto v0.58.0 h1:COkYLr4k7nDI4r6QtMML2AfzeIswWHAJthLS6K/M/54= |
| +golang.org/x/crypto v0.58.0/go.mod h1:Xh+kl5A+M0gMiWDytH2Hhr5Z7WbNCpv/eB/EFgfSk+w= |
| golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c= |
| golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o= |
| golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU= |
| golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg= |
| +golang.org/x/net v0.62.0 h1:18ELalfM5+XNRwzM2nYqXsZQ9ByS1uhj2O/U7+5jqRY= |
| +golang.org/x/net v0.62.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI= |
| golang.org/x/oauth2 v0.34.0 h1:hqK/t4AKgbqWkdkcAeI8XLmbK+4m4G5YeQRrmiotGlw= |
| golang.org/x/oauth2 v0.34.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA= |
| golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= |
| golang.org/x/sync v0.23.0 h1:KameEIfc1IkluZyXWLn39Wd4tURc6GbCiISGiZm2bQk= |
| golang.org/x/sync v0.23.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0= |
| +golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA= |
| +golang.org/x/sync v0.24.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0= |
| golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= |
| golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
| golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo= |
| golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= |
| +golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA= |
| +golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= |
| golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI= |
| golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E= |
| +golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc= |
| +golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s= |
| golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI= |
| golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4= |
| golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI= |
| golang.org/x/tools v0.49.0/go.mod h1:SJNXV9DBKT0UbdttsQjbfJlAE/q+y36++zo3uL3N0Oo= |
| +golang.org/x/tools v0.51.0 h1:k4Xc/1Om9jwkBJBo4NVLMSARBoWtK10mx+W5BnXCeAI= |
| +golang.org/x/tools v0.51.0/go.mod h1:9eEncMayCV6zRMGhR5eZEC2iBx98qWcF1HZ9Z7wJOoA= |
| golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= |
| google.golang.org/api v0.155.0 h1:vBmGhCYs0djJttDNynWo44zosHlPvHmA0XiN2zP2DtA= |
| google.golang.org/api v0.155.0/go.mod h1:GI5qK5f40kCpHfPn6+YzGAByIKWv8ujFnmoWm7Igduk= |
diff --git a/internal/console/securityheaders.go b/internal/console/securityheaders.go| new file mode 100644 |
| index 000000000..7479b4f4f |
| --- /dev/null |
| +++ b/internal/console/securityheaders.go |
| @@ -0,0 +1,13 @@ |
| +package console |
| + |
| +import "net/http" |
| + |
| +func (s *Server) browserSecurityHeaders(h http.Header) { |
| + h.Set("Content-Security-Policy", "frame-ancestors 'none'; object-src 'none'; base-uri 'self'") |
| + h.Set("X-Frame-Options", "DENY") |
| + h.Set("X-Content-Type-Options", "nosniff") |
| + h.Set("Referrer-Policy", "strict-origin-when-cross-origin") |
| + if s.secure { |
| + h.Set("Strict-Transport-Security", "max-age=86400") |
| + } |
| +} |
diff --git a/internal/console/securityheaders_test.go b/internal/console/securityheaders_test.go| new file mode 100644 |
| index 000000000..b4810a5f9 |
| --- /dev/null |
| +++ b/internal/console/securityheaders_test.go |
| @@ -0,0 +1,55 @@ |
| +package console |
| + |
| +import ( |
| + "net/http" |
| + "net/http/httptest" |
| + "testing" |
| +) |
| + |
| +func TestBrowserSecurityHeadersAcrossResponses(t *testing.T) { |
| + srv := newRedirectFixture(t, "https://console.example.test", []string{"dashboard.example.test"}) |
| + for _, tc := range []struct { |
| + name, method, host, path string |
| + status int |
| + }{ |
| + {"success", "GET", "console.example.test", "/healthz", 200}, |
| + {"authentication refusal", "GET", "console.example.test", "/auth/cli/whoami", 401}, |
| + {"missing asset", "GET", "console.example.test", "/static/unknown/missing.js", 404}, |
| + {"redirect", "GET", "dashboard.example.test", "/healthz", 301}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + rec := serveRedirect(t, srv, tc.method, tc.host, tc.path) |
| + if rec.Code != tc.status { |
| + t.Fatalf("status = %d, want %d", rec.Code, tc.status) |
| + } |
| + for name, want := range map[string]string{ |
| + "Content-Security-Policy": "frame-ancestors 'none'; object-src 'none'; base-uri 'self'", |
| + "X-Frame-Options": "DENY", |
| + "X-Content-Type-Options": "nosniff", |
| + "Referrer-Policy": "strict-origin-when-cross-origin", |
| + "Strict-Transport-Security": "max-age=86400", |
| + } { |
| + if got := rec.Header().Get(name); got != want { |
| + t.Errorf("%s = %q, want %q", name, got, want) |
| + } |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestBrowserSecurityHeadersHTTPOriginDoesNotEnableHSTS(t *testing.T) { |
| + srv := newRedirectFixture(t, "http://localhost:8080", nil) |
| + req := httptest.NewRequest(http.MethodGet, "/healthz", nil) |
| + req.Header.Set("X-Forwarded-Proto", "https") |
| + rec := httptest.NewRecorder() |
| + srv.ServeHTTP(rec, req) |
| + if rec.Code != http.StatusOK { |
| + t.Fatalf("status = %d", rec.Code) |
| + } |
| + if got := rec.Header().Get("Strict-Transport-Security"); got != "" { |
| + t.Fatalf("HTTP development origin received HSTS: %q", got) |
| + } |
| + if got := rec.Header().Get("X-Frame-Options"); got != "DENY" { |
| + t.Fatalf("frame denial = %q", got) |
| + } |
| +} |
diff --git a/internal/console/server.go b/internal/console/server.go| index 40786de4c..0f1c43eb0 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -2087,6 +2087,7 @@ func (s *Server) geoipPass(ctx context.Context) { |
| // ordering rule concerns account-existence leaks; a host-level redirect |
| // reveals nothing). |
| func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| + s.browserSecurityHeaders(w.Header()) |
| if s.redirects[normalizeHost(r.Host)] { |
| code := http.StatusMovedPermanently |
| if r.Method != http.MethodGet && r.Method != http.MethodHead { |
diff --git a/internal/moves/archive/zstd_malformed_test.go b/internal/moves/archive/zstd_malformed_test.go| new file mode 100644 |
| index 000000000..b7fa14259 |
| --- /dev/null |
| +++ b/internal/moves/archive/zstd_malformed_test.go |
| @@ -0,0 +1,57 @@ |
| +package archive |
| + |
| +import ( |
| + "bytes" |
| + "errors" |
| + "testing" |
| +) |
| + |
| +// malformedZstd is a zstd frame whose sequence decoding panicked |
| +// github.com/klauspost/compress before v1.20.2 (security review |
| +// 2026-11-09, zstd-probe). It must now fail as an ordinary decode error. |
| +func malformedZstd() []byte { |
| + b := []byte{0x28, 0xb5, 0x2f, 0xfd, 0x00, 0x38, 0x74, 0x06, 0x00, 0x42, 0xb8, 0x32, 0x0d, 0x1a, 0x00, 0x00, 0x00, 0x90, 0xaf, 0xfa, 0xff, 0x03, 0x00, 0x80, 0xff, 0x7f} |
| + b = append(b, bytes.Repeat([]byte{0xa5, 0x94, 0x52, 0x4a, 0x29}, 37)...) |
| + b = append(b, 0xa5, 0x94, 0x12, 0x00, 0xad, 0x56, 0x03, 0xee, 0xff, 0xdf, 0xb3, 0x1a, 0x1c, 0x1a, 0x00, 0xe0, 0xff, 0x1f, 0x0f, 0xb1, 0x9c, 0x5a, 0xcf, 0x4d, 0xe4, 0x1d, 0x7b, 0xab, 0x99, 0x5e, 0x01, 0x51, 0xa4, 0x73, 0xd8, 0xb1, 0xf3, 0x39, 0x4b, 0x67, 0xf6, 0xab, 0x1a, 0xab, 0x1a, 0xab, 0x1a) |
| + b = append(b, bytes.Repeat([]byte{0x8c, 0x31, 0xc6, 0x18, 0x63}, 1365)...) |
| + b = append(b, 0x8c, 0x31) |
| + b = append(b, bytes.Repeat([]byte{0x63, 0x8c, 0x31, 0xc6, 0x18}, 1365)...) |
| + b = append(b, 0x63, 0x2c) |
| + b = append(b, bytes.Repeat([]byte{0x31, 0xc6, 0x18, 0x63, 0x8c}, 1365)...) |
| + b = append(b, 0x31, 0x46) |
| + b = append(b, bytes.Repeat([]byte{0x31, 0xc6, 0x18, 0x63, 0x8c}, 1365)...) |
| + return append(b, 0x31, 0x06, 0x00) |
| +} |
| + |
| +// The malformed frame follows a valid frame holding a whole tar, so the |
| +// decoder only meets it when Extract and Verify read the decoded stream on |
| +// to its end (they do, to enforce decodedLimit); a frame in first position |
| +// would be refused by the tar reader before its bad block was decoded. |
| +func TestMalformedZstdFrameErrorsWithoutPanic(t *testing.T) { |
| + frame := append(tarZst(t, []rawEntry{reg("files/a", "x")}, nil), malformedZstd()...) |
| + |
| + t.Run("Extract", func(t *testing.T) { |
| + parent, files, env := extractTarget(t) |
| + if err := Extract(bytes.NewReader(frame), files, env); err == nil { |
| + t.Fatal("Extract accepted a malformed zstd frame") |
| + } |
| + assertUntouched(t, parent, files, env) |
| + }) |
| + |
| + t.Run("Verify", func(t *testing.T) { |
| + pub, priv, b := keys(t) |
| + var sealed bytes.Buffer |
| + key, sealedSHA, err := Seal(bytes.NewReader(frame), pub, b, &sealed) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + m := Manifest{V: ManifestVersion, Plain: "sha256:x", Sealed: sealedSHA, Bytes: 1, Entries: []Entry{{Path: "files/a", Size: 1, SHA256: digestBytes([]byte("x"))}}, SealedDataKey: key, Chunk: ChunkSize} |
| + err = Verify(bytes.NewReader(sealed.Bytes()), m, priv, b) |
| + if err == nil { |
| + t.Fatal("Verify accepted a malformed zstd frame") |
| + } |
| + if errors.Is(err, ErrTooLarge) { |
| + t.Fatalf("Verify = %v, want a decode error", err) |
| + } |
| + }) |
| +} |
diff --git a/internal/rootfsimage/zstd_malformed_test.go b/internal/rootfsimage/zstd_malformed_test.go| new file mode 100644 |
| index 000000000..abc446f30 |
| --- /dev/null |
| +++ b/internal/rootfsimage/zstd_malformed_test.go |
| @@ -0,0 +1,42 @@ |
| +package rootfsimage |
| + |
| +import ( |
| + "archive/tar" |
| + "bytes" |
| + "testing" |
| +) |
| + |
| +// malformedZstd is a zstd frame whose sequence decoding panicked |
| +// github.com/klauspost/compress before v1.20.2 (security review |
| +// 2026-11-09, zstd-probe). It must now fail as an ordinary decode error. |
| +func malformedZstd() []byte { |
| + b := []byte{0x28, 0xb5, 0x2f, 0xfd, 0x00, 0x38, 0x74, 0x06, 0x00, 0x42, 0xb8, 0x32, 0x0d, 0x1a, 0x00, 0x00, 0x00, 0x90, 0xaf, 0xfa, 0xff, 0x03, 0x00, 0x80, 0xff, 0x7f} |
| + b = append(b, bytes.Repeat([]byte{0xa5, 0x94, 0x52, 0x4a, 0x29}, 37)...) |
| + b = append(b, 0xa5, 0x94, 0x12, 0x00, 0xad, 0x56, 0x03, 0xee, 0xff, 0xdf, 0xb3, 0x1a, 0x1c, 0x1a, 0x00, 0xe0, 0xff, 0x1f, 0x0f, 0xb1, 0x9c, 0x5a, 0xcf, 0x4d, 0xe4, 0x1d, 0x7b, 0xab, 0x99, 0x5e, 0x01, 0x51, 0xa4, 0x73, 0xd8, 0xb1, 0xf3, 0x39, 0x4b, 0x67, 0xf6, 0xab, 0x1a, 0xab, 0x1a, 0xab, 0x1a) |
| + b = append(b, bytes.Repeat([]byte{0x8c, 0x31, 0xc6, 0x18, 0x63}, 1365)...) |
| + b = append(b, 0x8c, 0x31) |
| + b = append(b, bytes.Repeat([]byte{0x63, 0x8c, 0x31, 0xc6, 0x18}, 1365)...) |
| + b = append(b, 0x63, 0x2c) |
| + b = append(b, bytes.Repeat([]byte{0x31, 0xc6, 0x18, 0x63, 0x8c}, 1365)...) |
| + b = append(b, 0x31, 0x46) |
| + b = append(b, bytes.Repeat([]byte{0x31, 0xc6, 0x18, 0x63, 0x8c}, 1365)...) |
| + return append(b, 0x31, 0x06, 0x00) |
| +} |
| + |
| +// A layer blob that is a valid zstd frame (one tar header announcing a |
| +// regular file) followed by a malformed frame, which holds the file's body, |
| +// is refused by OpenLayout as an error, not a panic in the decoder. The |
| +// header comes first because the tar reader would refuse a malformed |
| +// frame in first position before its bad block was decoded. |
| +func TestOpenLayoutRefusesAMalformedZstdLayer(t *testing.T) { |
| + var hdr bytes.Buffer |
| + if err := tar.NewWriter(&hdr).WriteHeader(&tar.Header{Name: "f", Typeflag: tar.TypeReg, Mode: 0o644, Size: 1 << 20}); err != nil { |
| + t.Fatal(err) |
| + } |
| + layer := append(zstded(t, hdr.Bytes()), malformedZstd()...) |
| + dir := t.TempDir() |
| + writeLayout(t, dir, false, tImage{platform: "linux/arm64", layers: [][]byte{layer}}) |
| + if _, err := OpenLayout(dir, t.TempDir()); err == nil { |
| + t.Fatal("OpenLayout accepted a malformed zstd layer") |
| + } |
| +} |