Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func validate(w walker, refs []string, out *log.Logger) error {
}
}

for _, refName := range refs {
if err = refsNameRegexpCheck(refName); err != nil {
return err
}
}

for _, ref := range refs {
d, ok := ds[ref]
if !ok {
Expand Down Expand Up @@ -115,6 +121,10 @@ func Unpack(tarFile, dest, ref string) error {
}

func unpack(w walker, dest, refName string) error {
if err := refsNameRegexpCheck(refName); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced that we want to be doing validation as part of unpacking (folks who want it can call the validation code before calling unpack). But if that is not convincing, we can always add this for now, and remove it if/when someone gets around to filing a PR to pull the existing validation logic out of the unpacking code.

Copy link
Contributor Author

@TrumanLing TrumanLing Oct 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced that we want to be doing validation as part of unpacking (folks who want it can call the validation code before calling unpack).

I agree with you, but we can't avoid user's typing error. So I think, it is needed.

But if that is not convincing, we can always add this for now, and remove it if/when someone gets around to filing a PR to pull the existing validation logic out of the unpacking code.

Currently we add it like this, if there is better solution in the future, we will change to the better one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Sun, Oct 30, 2016 at 07:11:09PM -0700, TrumanLing wrote:

… but we can't avoid user's typing error…

That's not a problem. If the user typo's the ref name, unpacking will fail because the ref does not exist. Checking against the regexp in that case only “protects” you from the unlikely and presumably intentional case where the user is trying to unpack an illegal ref that already exists in the ref store. If the illegal ref is in the ref store it's not a compliant image, but I still think we should allow the user to unpack the ref (assuming the DAG it points to is unpackable).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I understand your concern. I will change it after PR in image-spec is merged, which leads to CI failure without merging it.

return err
}

ref, err := findDescriptor(w, refName)
if err != nil {
return err
Expand Down Expand Up @@ -157,6 +167,10 @@ func CreateRuntimeBundle(tarFile, dest, ref, root string) error {
}

func createRuntimeBundle(w walker, dest, refName, rootfs string) error {
if err := refsNameRegexpCheck(refName); err != nil {
return err
}

ref, err := findDescriptor(w, refName)
if err != nil {
return err
Expand Down Expand Up @@ -198,3 +212,10 @@ func createRuntimeBundle(w walker, dest, refName, rootfs string) error {

return json.NewEncoder(f).Encode(spec)
}

func refsNameRegexpCheck(refName string) error {
if boolRefsNameMatch := v1.RefsRegexp.MatchString(refName); !boolRefsNameMatch {
return fmt.Errorf("input parameter --ref (%s) is invalide", refName)
}
return nil
}