Skip to content

Commit

Permalink
feat: add feature file size limit
Browse files Browse the repository at this point in the history
Signed-off-by: AhmedGrati <[email protected]>
  • Loading branch information
TessaIO committed Sep 6, 2023
1 parent ade5833 commit 026534e
Show file tree
Hide file tree
Showing 2 changed files with 217 additions and 0 deletions.
20 changes: 20 additions & 0 deletions source/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const ExpiryTimeKey = "expiry-time"
// DirectivePrefix defines the prefix of directives that should be parsed
const DirectivePrefix = "# +"

// MaxFeatureFileSize defines the maximum size of a feature file size
const MaxFeatureFileSize = 64000

// Config
var (
featureFilesDir = "/etc/kubernetes/node-feature-discovery/features.d/"
Expand Down Expand Up @@ -321,6 +324,23 @@ func getFeaturesFromFiles() (map[string]string, error) {

for _, file := range files {
fileName := file.Name()

fileInfo, err := file.Info()
if err != nil {
klog.ErrorS(err, "failed to get file info", "fileName", fileName)
continue
}

fileSize := fileInfo.Size()
if fileSize > MaxFeatureFileSize {
klog.ErrorS(
fmt.Errorf("invalid file size: %d bytes > %d bytes", fileSize, MaxFeatureFileSize),
"skipping file with invalid size",
"fileName", fileName, "fileSize", fileSize,
)
continue
}

lines, err := getFileContent(fileName)
if err != nil {
klog.ErrorS(err, "failed to read file", "fileName", fileName)
Expand Down
197 changes: 197 additions & 0 deletions source/local/testdata/features.d/big_file

Large diffs are not rendered by default.

0 comments on commit 026534e

Please sign in to comment.