Skip to content

fix: do not panic on an invalid image name regexp#6184

Merged
kubernetes-prow[bot] merged 1 commit into
kubernetes-sigs:masterfrom
arpitjain099:fix/image-match-invalid-regex
Jul 15, 2026
Merged

fix: do not panic on an invalid image name regexp#6184
kubernetes-prow[bot] merged 1 commit into
kubernetes-sigs:masterfrom
arpitjain099:fix/image-match-invalid-regex

Conversation

@arpitjain099

Copy link
Copy Markdown
Contributor

Hi, I ran into a crash while working with an images override and traced it back to IsImageMatched in the api module.

The image name that comes from a kustomization's images[].name is interpolated straight into a regexp, and the compile error was discarded:

pattern, _ := regexp.Compile("^" + t + "(:[a-zA-Z0-9_.{}-]*)?...")
return pattern.MatchString(s)

If the name isn't a valid regexp (for example [), regexp.Compile returns (nil, err) and the following pattern.MatchString dereferences the nil *Regexp, so kustomize build panics with a SIGSEGV instead of failing cleanly. This is reachable in practice: a name like that in a remote base that you don't control (a common GitOps setup) takes down the whole build.

The fix keeps the exact same regex string and just checks the error, returning false when the name can't compile. That preserves the existing semantics, since a name that matches nothing leaves the image untouched, which is the same outcome you already get for any name that doesn't match a container.

Verification:

  • go test ./internal/image/ ./filters/imagetag/ passes.
  • Added a unit test in internal/image with the name [.
  • Added a krusty end-to-end case (a kustomization with images: [{name: "[", newTag: v2}] over a Deployment) that panics on master and builds through cleanly with this change.

Thanks for taking a look.

IsImageMatched interpolates the image name from kustomization images[].name
straight into a regexp and discarded the compile error. When the name is not
a valid regexp (for example "["), regexp.Compile returns a nil *Regexp and
the following MatchString call dereferences it, so kustomize build crashes with
a SIGSEGV.

Capture the compile error and return false when it is set. A name that can't
compile matches no image, which leaves the resource untouched (the same result
you get for any name that doesn't match). Adds a unit test for the invalid name
and a krusty end-to-end case that builds without panicking.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 10, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @arpitjain099!

It looks like this is your first PR to kubernetes-sigs/kustomize 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kustomize has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow

Copy link
Copy Markdown
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

@kubernetes-prow kubernetes-prow Bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 10, 2026
@koba1t

koba1t commented Jul 12, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@kubernetes-prow kubernetes-prow Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 12, 2026
@koba1t

koba1t commented Jul 15, 2026

Copy link
Copy Markdown
Member

@arpitjain099
Thank you for your contribution!
I think this is a bug that we need to be fixed.

/lgtm
/approve

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 15, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: arpitjain099, koba1t

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 15, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit f36fdc7 into kubernetes-sigs:master Jul 15, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants