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

Protect against overflows in BoxedFlagValues #109

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

huwr
Copy link
Contributor

@huwr huwr commented Mar 17, 2023

📒 Description

Previously, attempting to unwrap an Int from a BoxedFlagValue into an FlagValue that was not wide enough would cause a runtime error.

Now, we unwrap the Int from the BoxedFlagValue and convert it into the Int type’s fallible initialiser. That way, we know it will not be too big when we do the assignment.

🗳 Test Plan

  • Unit tests included for all Int types (except Int64, which is a little harder)

✅ Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

😠 Not finished

It's not finished. Somehow, there's double-optionals are making it into the UserDefaults FlagValueSource's set value function.

    /// Sets the value for the specified key
    public func setFlagValue<Value>(_ value: Value?, key: String) throws where Value: FlagValue {
        guard let value = value else { // unwraps a UInt16?? to UInt16? It must be `.some(nil)`
            self.removeObject(forKey: key)
            return
        }

        self.set(value.boxedFlagValue.object, forKey: key) // tries to send nil `UInt16?` in here, which fails.
    }

I shall ponder because I'm not sure why they're double-optionalised now.

huwr added 2 commits March 17, 2023 11:49
Previously, attempting to unwrap an Int from a BoxedFlagValue into an FlagValue that was not wide enough would cause a runtime error.

Now, we unwrap the Int from the BoxedFlagValue and convert it into the Int type’s fallible initialiser. That way, we know it will not be too big when we do the assignment.
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

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.

1 participant