Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent cache size underflow #4986

Merged
merged 1 commit into from
Feb 6, 2025
Merged

fix: prevent cache size underflow #4986

merged 1 commit into from
Feb 6, 2025

Conversation

acha-bill
Copy link
Contributor

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

Prevent cache size from underflowing

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

#4982

Screenshots (if appropriate):

@acha-bill acha-bill requested a review from istae as a code owner February 5, 2025 05:21
@istae
Copy link
Member

istae commented Feb 5, 2025

Has the underflow happened in production?

@gacevicljubisa
Copy link
Contributor

gacevicljubisa commented Feb 5, 2025

Size filed is of type Int64, so negative number are allowed.

type Cache struct {
	size     atomic.Int64
	capacity int
	glock    *multex.Multex // blocks Get and Put ops while shallow copy is running.
}

@acha-bill
Copy link
Contributor Author

Has the underflow happened in production?

Only mentioned in #4982

Size filed is of type Int64, so negative number are allowed.

But when returning, it's cast to uint64. This causes the underflow to MaxUint64 if size was < 0

@gacevicljubisa
Copy link
Contributor

Has the underflow happened in production?

Only mentioned in #4982

Size filed is of type Int64, so negative number are allowed.

But when returning, it's cast to uint64. This causes the underflow to MaxUint64 if size was < 0

Then we should return error if size is 0 or less, right? Is it allowed to be 0 or less and in which cases?

@acha-bill acha-bill force-pushed the fix/cache-underflow branch from 70ebd05 to d56ae07 Compare February 6, 2025 15:31
@acha-bill acha-bill merged commit 38a57ef into master Feb 6, 2025
15 checks passed
@acha-bill acha-bill deleted the fix/cache-underflow branch February 6, 2025 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants