diff --git a/SOURCES/file-5.41-python-magic-threads.patch b/SOURCES/file-5.41-python-magic-threads.patch new file mode 100644 index 0000000..9636840 --- /dev/null +++ b/SOURCES/file-5.41-python-magic-threads.patch @@ -0,0 +1,77 @@ +diff --git a/python/magic.py b/python/magic.py +index 662569e..2be58cd 100644 +--- a/python/magic.py ++++ b/python/magic.py +@@ -5,6 +5,7 @@ Python bindings for libmagic + ''' + + import ctypes ++import threading + + from collections import namedtuple + +@@ -241,11 +242,25 @@ def open(flags): + + + # Objects used by `detect_from_` functions +-mime_magic = Magic(_open(MAGIC_MIME)) +-mime_magic.load() +-none_magic = Magic(_open(MAGIC_NONE)) +-none_magic.load() +- ++class MagicDetect(object): ++ def __init__(self): ++ self.mime_magic = Magic(_open(MAGIC_MIME)) ++ self.mime_magic.load() ++ self.none_magic = Magic(_open(MAGIC_NONE)) ++ self.none_magic.load() ++ ++ def __del__(self): ++ self.mime_magic.close() ++ self.none_magic.close() ++ ++threadlocal = threading.local() ++ ++def _detect_make(): ++ v = getattr(threadlocal, "magic_instance", None) ++ if v is None: ++ v = MagicDetect() ++ setattr(threadlocal, "magic_instance", v) ++ return v + + def _create_filemagic(mime_detected, type_detected): + mime_type, mime_encoding = mime_detected.split('; ') +@@ -259,9 +274,9 @@ def detect_from_filename(filename): + + Returns a `FileMagic` namedtuple. + ''' +- +- return _create_filemagic(mime_magic.file(filename), +- none_magic.file(filename)) ++ x = _detect_make() ++ return _create_filemagic(x.mime_magic.file(filename), ++ x.none_magic.file(filename)) + + + def detect_from_fobj(fobj): +@@ -271,8 +286,9 @@ def detect_from_fobj(fobj): + ''' + + file_descriptor = fobj.fileno() +- return _create_filemagic(mime_magic.descriptor(file_descriptor), +- none_magic.descriptor(file_descriptor)) ++ x = _detect_make() ++ return _create_filemagic(x.mime_magic.descriptor(file_descriptor), ++ x.none_magic.descriptor(file_descriptor)) + + + def detect_from_content(byte_content): +@@ -281,5 +297,6 @@ def detect_from_content(byte_content): + Returns a `FileMagic` namedtuple. + ''' + +- return _create_filemagic(mime_magic.buffer(byte_content), +- none_magic.buffer(byte_content)) ++ x = _detect_make() ++ return _create_filemagic(x.mime_magic.buffer(byte_content), ++ x.none_magic.buffer(byte_content)) diff --git a/SPECS/file.spec b/SPECS/file.spec index 4b57113..3eb7468 100644 --- a/SPECS/file.spec +++ b/SPECS/file.spec @@ -15,7 +15,7 @@ Summary: A utility for determining file types Name: file Version: 5.33 -Release: 25%{?dist} +Release: 26%{?dist} License: BSD Group: Applications/File Source0: ftp://ftp.astron.com/pub/file/file-%{version}.tar.gz @@ -107,6 +107,9 @@ Patch30: file-5.33-static-PIE-binaries-5.patch # https://github.com/file/file/commit/39e43a669d1260f0df36f0b2e78b3012ffd5f086 (#2158115) Patch31: file-5.33-thermocam-magic.patch +# Upstream commit c8deb32eab1089d1841482fb2e91833f114b6712 (#13737) +Patch32: file-5.41-python-magic-threads.patch + URL: http://www.darwinsys.com/file/ Requires: file-libs = %{version}-%{release} BuildRequires: zlib-devel @@ -278,6 +281,9 @@ cd %{py3dir} %endif %changelog +* Thu Oct 12 2023 Vincent Mihalkovic - 5.33-26 +- Fix segfault in python3-file-magic concurrent method calls (#13737) + * Thu Apr 20 2023 Vincent Mihalkovic - 5.33-25 - Improve thermocam magic (rhbz#2158115)