13
0
Fork 0
mirror of https://github.com/yannh/kubeconform.git synced 2026-06-29 16:30:44 +00:00
kubeconform/pkg/resource
Nikolai Emil Damm d3ae574bf2
fix: copy scanner bytes in FromStream to prevent aliasing data race
FromStream set each Resource's Bytes to scanner.Bytes(), which aliases
the bufio.Scanner's internal buffer. Resources are emitted on a channel
and retained/parsed by the consumer concurrently with the producer
goroutine; when the scanner refills its buffer for later documents it
overwrites the slices earlier Resources still point at. Consumers that
parse resources as they arrive (e.g. ValidateWithContext) then read
corrupted bytes — a later document spliced into the one being parsed —
surfacing as non-deterministic YAML parse errors on large multi-document
streams (a different resource fails on each run).

Clone the scanner bytes so each Resource owns its slice. Adds a
regression test that streams >4MB (forcing the scanner to refill) and
asserts every resource's bytes are intact after draining.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 02:50:27 +02:00
..
files.go Small fixes, better sanitization (#359) 2026-06-04 21:55:22 +02:00
files_test.go add tests for yaml scanning 2021-01-02 14:06:13 +01:00
resource.go Allow to skip resources using the GVK notation (#92) 2022-10-16 14:59:48 +02:00
resource_test.go Reformat strings 2021-07-03 16:01:51 +02:00
stream.go fix: copy scanner bytes in FromStream to prevent aliasing data race 2026-06-25 02:50:27 +02:00
stream_test.go fix: copy scanner bytes in FromStream to prevent aliasing data race 2026-06-25 02:50:27 +02:00