From 5561bc29001899b2762baa5bf1561ec8648ebc5c Mon Sep 17 00:00:00 2001 From: Egor Ignatov Date: Tue, 3 Nov 2026 20:27:49 +0500 Subject: [PATCH 1/3] Fix NULL_COLOR_VALUE on 32-bit platforms Export NULL_COLOR_VALUE using PyLong_FromUnsignedLong instead of PyModule_AddIntMacro, which converts it to a signed long. On 32-bit platforms this turns 0xffffffff into -1 and causes the generated Go uint32 constant to overflow, preventing kitten from building. Add a regression check for the exported value. --- kitty/colors.c | 4 +++- kitty_tests/screen.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/kitty/colors.c b/kitty/colors.c index 480d6737d..941695d61 100644 --- a/kitty/colors.c +++ b/kitty/colors.c @@ -1890,7 +1890,9 @@ init_ColorProfile(PyObject *module) { Py_INCREF(&Color_Type); if (PyModule_AddFunctions(module, module_methods) != 0) return false; - PyModule_AddIntMacro(module, NULL_COLOR_VALUE); + // PyModule_AddIntMacro converts to signed long, which overflows on 32-bit platforms. + RAII_PyObject(null_color_value, PyLong_FromUnsignedLong(NULL_COLOR_VALUE)); + if (!null_color_value || PyModule_AddObjectRef(module, "NULL_COLOR_VALUE", null_color_value) != 0) return 0; PyModule_AddIntMacro(module, COLOR_LAYER_OVERRIDE); PyModule_AddIntMacro(module, COLOR_LAYER_GLOBAL); PyModule_AddIntMacro(module, COLOR_LAYER_WINDOW); diff --git a/kitty_tests/screen.py b/kitty_tests/screen.py index b2c12ad27..4b2990d92 100644 --- a/kitty_tests/screen.py +++ b/kitty_tests/screen.py @@ -2581,8 +2581,9 @@ class TestScreen(BaseTest): self.assertNotIn('mark1_background', cp.as_dict()) def test_color_profile(self): - from kitty.fast_data_types import patch_color_profiles + from kitty.fast_data_types import NULL_COLOR_VALUE, patch_color_profiles + self.ae(NULL_COLOR_VALUE, 0xFFFFFFFF) opts = self.set_options({'palette_generate': 'fixed'}) c = ColorProfile(opts) for i in range(8): From 0b1b477409db20f5ae811e158925b7d5e9595a11 Mon Sep 17 00:00:00 2001 From: Egor Ignatov Date: Tue, 3 Nov 2026 20:36:29 +0500 Subject: [PATCH 2/3] Fix special color encoding on 32-bit platforms Use int64 for encoded special colors so RGB values shifted into the upper three bytes remain positive on 32-bit platforms, while preserving the negative sentinel values used for macOS titlebar colors. Update the tests to use the same type, avoiding overflowing int constants when compiling them on 32-bit platforms. --- tools/cmd/at/set_colors.go | 6 +++--- tools/cmd/at/set_colors_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/cmd/at/set_colors.go b/tools/cmd/at/set_colors.go index 9a9373f50..c58a94fd4 100644 --- a/tools/cmd/at/set_colors.go +++ b/tools/cmd/at/set_colors.go @@ -297,7 +297,7 @@ var special_color_values = map[string]map[string]int{ // Encode a color that accepts special values the same way as // color_with_special_values() in kitty/options/utils.py: special values are // stored in the lowest byte and actual colors are shifted into the upper bytes. -func encode_special_color(key, val string) (int, error) { +func encode_special_color(key, val string) (int64, error) { special_values, found := special_color_values[key] if !found { return 0, fmt.Errorf("The special values for the color %s are not known", key) @@ -312,13 +312,13 @@ func encode_special_color(key, val string) (int, error) { } } if ans, found := special_values[val]; found { - return ans, nil + return int64(ans), nil } col, err := style.ParseColor(val) if err != nil { return 0, fmt.Errorf("%s is not a valid color", val) } - return int(col.AsRGB())<<8 | len(special_values), nil + return int64(col.AsRGB())<<8 | int64(len(special_values)), nil } func set_color_in_color_map(key, val string, ans map[string]any, check_nullable, skip_nullable bool) error { diff --git a/tools/cmd/at/set_colors_test.go b/tools/cmd/at/set_colors_test.go index c5595a691..2749463d2 100644 --- a/tools/cmd/at/set_colors_test.go +++ b/tools/cmd/at/set_colors_test.go @@ -74,7 +74,7 @@ func TestSetColorsConfFiles(t *testing.T) { expected := map[string]any{ "foreground": uint32(0xff0000), "background": uint32(0xff), "cursor": nil, "selection_background": uint32(0xff00), "color1": uint32(0xaaaaaa), - "wayland_titlebar_color": 1, + "wayland_titlebar_color": int64(1), } if len(payload.Colors) != len(expected) { t.Fatalf("unexpected colors parsed from conf file: %#v", payload.Colors) @@ -101,7 +101,7 @@ func TestSetColorsSpecialColors(t *testing.T) { // expected values are from kitty.colors.parse_colors() for _, test := range []struct { arg string - expected int + expected int64 }{ {"wayland_titlebar_color=#123456", 0x12345602}, {"wayland_titlebar_color=system", 0}, From 51b159f9900896182aa708e27db7fc9851a3e654 Mon Sep 17 00:00:00 2001 From: Egor Ignatov Date: Tue, 3 Nov 2026 20:36:29 +0500 Subject: [PATCH 3/3] Fix PNG dimension validation test on 32-bit platforms Expect OverflowError for dimensions that exceed sys.maxsize, since PyArg_ParseTuple rejects them before the PNG buffer validation runs. Continue to expect ValueError for invalid dimensions and buffer lengths that reach the validation code. --- kitty_tests/datatypes.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kitty_tests/datatypes.py b/kitty_tests/datatypes.py index 9eb089d69..0b3172116 100644 --- a/kitty_tests/datatypes.py +++ b/kitty_tests/datatypes.py @@ -116,7 +116,10 @@ class TestDataTypes(BaseTest): (rgba, 2**32 + 2, 2), (rgba, -2, -2), ): - with self.assertRaises(ValueError, msg=repr(args[1:])): + # Dimensions outside Py_ssize_t fail during argument parsing, before + # the buffer length and dimension validation can raise ValueError. + error = OverflowError if any(x > sys.maxsize for x in args[1:]) else ValueError + with self.assertRaises(error, msg=repr(args[1:])): png_from_32bit_rgba_data(*args) with self.assertRaises(OverflowError): png_from_32bit_rgba_data(rgba, 2, 2**64 + 2)