Skip to content

Commit

Permalink
Prevent parsing negative numbers as uint
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Mar 10, 2023
1 parent 5a00c9f commit aee6224
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"math"
"os"
"path/filepath"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -867,20 +866,15 @@ func (fs *Decomposedfs) storageSpaceFromNode(ctx context.Context, n *node.Node,
}

// quota
quotaAttr, ok := spaceAttributes[prefixes.QuotaAttr]
if ok {
if q, err := spaceAttributes.Int64(prefixes.QuotaAttr); err == nil && q >= 0 {
// make sure we have a proper signed int
// we use the same magic numbers to indicate:
// -1 = uncalculated
// -2 = unknown
// -3 = unlimited
if quota, err := strconv.ParseUint(string(quotaAttr), 10, 64); err == nil {
space.Quota = &provider.Quota{
QuotaMaxBytes: quota,
QuotaMaxFiles: math.MaxUint64, // TODO MaxUInt64? = unlimited? why even max files? 0 = unlimited?
}
} else {
return nil, err
space.Quota = &provider.Quota{
QuotaMaxBytes: uint64(q),
QuotaMaxFiles: math.MaxUint64, // TODO MaxUInt64? = unlimited? why even max files? 0 = unlimited?
}
}
if si := spaceAttributes.String(prefixes.SpaceImageAttr); si != "" {
Expand Down

0 comments on commit aee6224

Please sign in to comment.