From 10bd43664948708717c06b55ff5ac341d79da1b5 Mon Sep 17 00:00:00 2001 From: godoy <95002561+herniqeu@users.noreply.github.com> Date: Sun, 1 Nov 2026 02:30:54 -0300 Subject: [PATCH 1/2] Pass a full-width size_t to the compat setparam/getparam libmagic reads and writes the value of magic_setparam/magic_getparam as a size_t, but magic/compat.py built a c_int buffer instead. On 64-bit that truncated values above 32 bits before they reached libmagic (and getparam let libmagic write 8 bytes into a 4-byte buffer). magic/__init__.py already uses c_size_t; only the compat layer was left behind. --- magic/compat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/magic/compat.py b/magic/compat.py index 32a7b93b..dbac9dfc 100644 --- a/magic/compat.py +++ b/magic/compat.py @@ -244,7 +244,7 @@ def getparam(self, param): Returns the param value if successful and -1 if the parameter was unknown. """ - v = c_int() + v = c_size_t() i = _getparam(self._magic_t, param, byref(v)) if i == -1: return -1 @@ -254,7 +254,7 @@ def setparam(self, param, value): """ Returns 0 if successful and -1 if the parameter was unknown. """ - v = c_int(value) + v = c_size_t(value) return _setparam(self._magic_t, param, byref(v)) From 29b292f37e5693e1c75444340487765865342e61 Mon Sep 17 00:00:00 2001 From: godoy <95002561+herniqeu@users.noreply.github.com> Date: Sun, 1 Nov 2026 02:30:55 -0300 Subject: [PATCH 2/2] Test that compat setparam/getparam keep 64-bit values --- test/python_magic_test.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/python_magic_test.py b/test/python_magic_test.py index 26398614..48d9e558 100755 --- a/test/python_magic_test.py +++ b/test/python_magic_test.py @@ -191,6 +191,14 @@ def test_version(self): except NotImplementedError: pass + + def test_compat_params_use_size_t(self): + # libmagic reads and writes setparam/getparam values as a size_t, + # so the compat module must not truncate them to 32 bits. + m = magic.compat.open(magic.compat.MAGIC_NONE) + self.assertEqual(0, m.setparam(magic.compat.PARAM_BYTES_MAX, 2**33)) + self.assertEqual(2**33, m.getparam(magic.compat.PARAM_BYTES_MAX)) + def test_fs_encoding(self): self.assertEqual("utf-8", sys.getfilesystemencoding().lower())