Internal change.

PiperOrigin-RevId: 327892274
This commit is contained in:
gVisor bot 2020-08-21 16:18:31 -07:00
parent 0ea03f501b
commit 23070b2e5f
2 changed files with 10 additions and 1 deletions

View File

@ -33,3 +33,12 @@ func FromContext(ctx context.Context) *LimitSet {
}
return nil
}
// FromContextOrDie returns FromContext(ctx) if the latter is not nil.
// Otherwise, panic is triggered.
func FromContextOrDie(ctx context.Context) *LimitSet {
if v := ctx.Value(CtxLimits); v != nil {
return v.(*LimitSet)
}
panic("failed to create limit set from context")
}

View File

@ -271,7 +271,7 @@ func HasCapabilityOnFile(creds *auth.Credentials, cp linux.Capability, kuid auth
// operation must not proceed. Otherwise it returns the max length allowed to
// without violating the limit.
func CheckLimit(ctx context.Context, offset, size int64) (int64, error) {
fileSizeLimit := limits.FromContext(ctx).Get(limits.FileSize).Cur
fileSizeLimit := limits.FromContextOrDie(ctx).Get(limits.FileSize).Cur
if fileSizeLimit > math.MaxInt64 {
return size, nil
}