Skip to content

Commit

Permalink
Return an error if 'porchctl push' detects a binary file in the kpt p…
Browse files Browse the repository at this point in the history
…ackage
  • Loading branch information
kispaljr committed Jun 28, 2024
1 parent 75548f8 commit 4dcaadc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/cli/commands/rpkg/push/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"path"
"path/filepath"
"strings"
"unicode/utf8"

porchapi "github.com/nephio-project/porch/api/porch/v1alpha1"
"github.com/nephio-project/porch/internal/kpt/errors"
Expand Down Expand Up @@ -241,6 +242,13 @@ func readFromDir(dir string) (map[string]string, error) {
if err != nil {
return err
}
if !utf8.Valid(contents) {
// Since PackageRevisionResources' spec.Resources is a map of strings, during JSON serialization all file contents
// will be converted to valid UTF-8 by changing invalid bytes to the Unicode replacement character.
// This of course corrupts the contents of binary files.
// Return an early error here to prevent pushing corrupt content.
return fmt.Errorf("file %s is not a valid UTF-8 text file: current porch API doesn't support binary files", path)
}
resources[rel] = string(contents)
return nil
}); err != nil {
Expand Down

0 comments on commit 4dcaadc

Please sign in to comment.