Guard the empty-file case when loading CRDs - #6209
Conversation
makeNameToApiMap indexed content[0] to decide between JSON and YAML, so a crds entry pointing at a zero-byte file crashed kustomize build with an index out of range instead of contributing no CRDs. The length check matches the existing idiom in kyaml/openapi. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
|
Hi @arpitjain099. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/ok-to-test |
saitejabandaru-in
left a comment
There was a problem hiding this comment.
LGTM! This elegantly handles the empty file edge case and prevents the slice bounds out of range panic. The unit test also properly covers this scenario.
saitejabandaru-in
left a comment
There was a problem hiding this comment.
LGTM! This perfectly guards against the out-of-bounds index on empty files.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: arpitjain099, saitejabandaru-in The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
A
crds:entry that points at a zero-byte file crashes the build:makeNameToApiMaplooks at the first byte to decide between JSON and YAML:kustomization.yamlcrds:takes relative paths,kusttarget.gohands each file toLoadConfigFromCRDs, and nothing checks the contents are non-empty on the way. So an empty file in that list panics rather than contributing no CRDs. A whitespace-only file does not trip it, since a space just routes to the YAML branch, which is what made this specific to zero-length files.The fix uses the same shape the repo already uses in
kyaml/openapi/openapi.go:An empty file then goes to
yaml.Unmarshal([]byte{}), which returns a nil map and no error, so it contributes nothing.Test added next to
TestLoadCRDs. It panics on master and passes with the change;go test ./internal/accumulator/is green.