unsignedapps / Vexil

Vexil (named for Vexillology) is a Swift package for managing feature flags (also called feature toggles) in a flexible, multi-provider way.
https://vexil.unsignedapps.com
MIT License
114 stars 11 forks source link

Protect against overflows in BoxedFlagValues #109

Open huwr opened 1 year ago

huwr commented 1 year ago

📒 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

✅ Checklist

😠 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.

sonarcloud[bot] commented 1 year ago

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