You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CefSettings.ColorType: alpha >= 0x80 sign-extends into a negative long, not the intended unsigned ARGB value #8
CefSettings.ColorType's packing constructor computes the ARGB value entirely in
32-bit int arithmetic, then relies on implicit widening to store it into the long color_value field:
When alpha >= 0x80, (alpha << 24) sets the sign bit of the intermediate int
result, making the whole packed expression a negative int. Java's implicit int -> long widening then sign-extends that negative value, so color_value
ends up with all of the long's upper 32 bits set to 1 -- not the plain
unsigned 32-bit ARGB value a caller would reasonably expect from a field typed long specifically to represent one.
Low alpha values (< 0x80) are unaffected -- e.g. new ColorType(0x7F, 0x11, 0x22, 0x33)
correctly returns 0x7F112233L.
Impact
Any caller comparing getColor() against an expected unsigned ARGB long constant,
or otherwise treating the field as an unsigned 32-bit color value (as the class's
own Javadoc describes: "32-bit ARGB color value, not premultiplied"), will get
surprising results whenever alpha is >= 0x80 -- which includes the common case of a
fully-opaque color (alpha = 0xFF).
Suggested fix
Mask to 32 bits (or build the value with long-typed intermediate arithmetic) before
assigning to color_value, e.g.:
color_value = ((long) alpha << 24 | (long) red << 16 | (long) green << 8 | blue) & 0xFFFFFFFFL;
Found via
Writing CefSettingsTest.java (new unit tests, coverage-expansion effort tracked in #5)
-- see colorTypeHighAlphaSignExtends(), which documents the current (buggy) behavior
with an explanatory comment rather than silently masking it.
Fixed. CefSettings.ColorType's constructor now packs in long-typed arithmetic and masks to 32 bits, exactly as suggested:
color_value = ((long) alpha << 24 | (long) red << 16 | (long) green << 8 | blue) & 0xFFFFFFFFL;
Verified: new ColorType(0xFF, 0x11, 0x22, 0x33).getColor() now returns 0xFF112233L instead of the sign-extended 0xFFFFFFFFFF112233L. Updated CefSettingsTest.colorTypeHighAlphaSignExtends() (renamed to colorTypeHighAlphaDoesNotSignExtend()) to assert the correct value as a regression test instead of documenting the bug. Full suite for this class: 6/6 passing.
Activity
Thrameos commentedon Aug 31, 2026
Fixed.
CefSettings.ColorType's constructor now packs inlong-typed arithmetic and masks to 32 bits, exactly as suggested:Verified:
new ColorType(0xFF, 0x11, 0x22, 0x33).getColor()now returns0xFF112233Linstead of the sign-extended0xFFFFFFFFFF112233L. UpdatedCefSettingsTest.colorTypeHighAlphaSignExtends()(renamed tocolorTypeHighAlphaDoesNotSignExtend()) to assert the correct value as a regression test instead of documenting the bug. Full suite for this class: 6/6 passing.Fix issue #8: ColorType(int,int,int,int) sign-extends on high alpha
Fix issue #8: ColorType(int,int,int,int) sign-extends on high alpha
Merge pull request #36 from Thrameos/backport/colortype-alpha-sign-ex…