Skip to content

AddressSanitizer: heap-buffer-overflow UIColor+KVNContrast.m:16 in -[UIColor(KVNContrast) statusBarStyleConstrastStyle] #123

@andriy-appuchino

Description

@andriy-appuchino

After running my app through the AddressSanitizer I got a heap buffer overflow error.
The lines causing that are in UIColor+KVNContrast.h extension in - (UIStatusBarStyle)statusBarStyleConstrastStyle.

	const CGFloat *componentColors = CGColorGetComponents(self.CGColor);
	CGFloat darknessScore = (((componentColors[0] * 255) * 299) + ((componentColors[1] * 255) * 587) + ((componentColors[2] * 255) * 114)) / 1000;

CGColorGetComponents is not guaranteed to return 3 components in all cases.
To fix that, please replace the lines above with the following:

	CGFloat red, green, blue;
	[self getRed:&red green:&green blue:&blue alpha:nil];
	CGFloat darknessScore = (((red * 255) * 299) + ((green * 255) * 587) + ((blue * 255) * 114)) / 1000;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions