Cleanup and python 3.13

This commit is contained in:
Mario Fetka
2025-05-05 10:23:40 +02:00
parent 7c1ee4ca45
commit b56141d74d
121 changed files with 9006 additions and 479 deletions

View File

@@ -0,0 +1,55 @@
From 57190699030dc6746320e49695a67ce83c62d549 Mon Sep 17 00:00:00 2001
From: Kovid Goyal <kovid@kovidgoyal.net>
Date: Sun, 28 May 2023 14:03:15 +0530
Subject: [PATCH] HTML Input: Dont add resources that exist outside the folder
hierarchy rooted at the parent folder of the input HTML file by default
(cherry picked from commit bbbddd2bf4ef4ddb467b0aeb0abe8765ed7f8a6b)
---
.../ebooks/conversion/plugins/html_input.py | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/calibre/ebooks/conversion/plugins/html_input.py b/src/calibre/ebooks/conversion/plugins/html_input.py
index 6f9c2084ea..742f3e0279 100644
--- a/src/calibre/ebooks/conversion/plugins/html_input.py
+++ b/src/calibre/ebooks/conversion/plugins/html_input.py
@@ -64,6 +64,16 @@ class HTMLInput(InputFormatPlugin):
)
),
+ OptionRecommendation(name='allow_local_files_outside_root',
+ recommended_value=False, level=OptionRecommendation.LOW,
+ help=_('Normally, resources linked to by the HTML file or its children will only be allowed'
+ ' if they are in a sub-folder of the original HTML file. This option allows including'
+ ' local files from any location on your computer. This can be a security risk if you'
+ ' are converting untrusted HTML and expecting to distribute the result of the conversion.'
+ )
+ ),
+
+
}
def convert(self, stream, opts, file_ext, log,
@@ -76,6 +86,7 @@ def convert(self, stream, opts, file_ext, log,
if hasattr(stream, 'name'):
basedir = os.path.dirname(stream.name)
fname = os.path.basename(stream.name)
+ self.root_dir_of_input = os.path.abspath(basedir) + os.sep
if file_ext != 'opf':
if opts.dont_package:
@@ -250,6 +261,11 @@ def link_to_local_path(self, link_, base=None):
frag = l.fragment
if not link:
return None, None
+ link = os.path.abspath(os.path.realpath(link))
+ if not link.startswith(self.root_dir_of_input):
+ if not self.opts.allow_local_files_outside_root:
+ self.log.warn('Not adding {} as it is outside the document root: {}'.format(link, self.root_dir_of_input))
+ return None, None
return link, frag
def resource_adder(self, link_, base=None):
--
2.41.0

View File

@@ -0,0 +1,36 @@
From a961ddbfcb96461fd830ccd6facb81d69cc679d8 Mon Sep 17 00:00:00 2001
From: Kovid Goyal <kovid@kovidgoyal.net>
Date: Tue, 29 Oct 2024 06:08:04 +0530
Subject: [PATCH] PIL 11.0 changes its webp features output
---
src/calibre/test_build.py | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py
index 4e3d740705..91c32eba38 100644
--- a/src/calibre/test_build.py
+++ b/src/calibre/test_build.py
@@ -436,16 +436,14 @@ def test_imaging(self):
out = StringIO()
features.pilinfo(out=out, supported_formats=False)
out = out.getvalue()
- for line in '''\
+ lines = '''\
--- PIL CORE support ok
--- FREETYPE2 support ok
--- WEBP support ok
- --- WEBP Transparency support ok
- --- WEBPMUX support ok
- --- WEBP Animation support ok
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
- '''.splitlines():
+ '''.splitlines()
+ for line in lines:
self.assertIn(line.strip(), out)
with Image.open(I('lt.png', allow_user_override=False)) as i:
self.assertGreaterEqual(i.size, (20, 20))
--
2.45.2

View File

@@ -0,0 +1,24 @@
Avoid calling libjxr's JxrDecApp as we currently don't package it.
--- a/src/calibre/utils/img.py
+++ b/src/calibre/utils/img.py
@@ -118,8 +118,6 @@
i = QImage()
if not i.loadFromData(data):
q = what(None, data)
- if q == 'jxr':
- return load_jxr_data(data)
raise NotImage(f'Not a valid image (detected type: {q})')
return i
@@ -645,11 +643,6 @@
despeckle_image(img)
remove_borders_from_image(img)
image_to_data(img, fmt='GIF')
- raw = subprocess.Popen([get_exe_path('JxrDecApp'), '-h'],
- creationflags=subprocess.DETACHED_PROCESS if iswindows else 0,
- stdout=subprocess.PIPE).stdout.read()
- if b'JPEG XR Decoder Utility' not in raw:
- raise SystemExit('Failed to run JxrDecApp')
# }}}

View File

@@ -0,0 +1,26 @@
From 5d8d85c649b181747d182f676cfd76f843bd61f0 Mon Sep 17 00:00:00 2001
From: Kovid Goyal <kovid@kovidgoyal.net>
Date: Sun, 1 Oct 2023 15:08:59 +0530
Subject: [PATCH] Fix compatibility with zeroconf >= 0.73
Fixes #2038 (fix compatibility with newer zeroconf)
---
src/calibre/devices/smart_device_app/driver.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/calibre/devices/smart_device_app/driver.py b/src/calibre/devices/smart_device_app/driver.py
index 87608f305b..b41c3a0063 100644
--- a/src/calibre/devices/smart_device_app/driver.py
+++ b/src/calibre/devices/smart_device_app/driver.py
@@ -2175,6 +2175,8 @@ def monkeypatch_zeroconf():
# "monkeypatch" zeroconf with a function without the check
try:
from zeroconf._utils.name import service_type_name
+ # zeroconf 0.73 uses an lru cache so we need __wrapped__
+ service_type_name = getattr(service_type_name, '__wrapped__', service_type_name)
service_type_name.__kwdefaults__['strict'] = False
except ImportError:
import zeroconf
--
2.41.0

View File

@@ -0,0 +1,28 @@
logical changes backported from:
https://github.com/kovidgoyal/calibre/commit/a3d3d8d33e314ccabb5099e78e4056a79b7c9aa2
https://bugs.gentoo.org/936270
diff -rup a/setup/build.py b/setup/build.py
--- a/setup/build.py 2022-06-17 04:35:27.000000000 +0200
+++ b/setup/build.py 2024-07-19 11:51:56.374389213 +0200
@@ -65,6 +65,8 @@ class Extension:
self.cflags.insert(0, '-std=c++11')
elif kwargs.get('needs_c++14'):
self.cflags.insert(0, '-std=c++14')
+ elif kwargs.get('needs_c++17'):
+ self.cflags.insert(0, '-std=c++17')
else:
if kwargs.get('needs_c99'):
self.cflags.insert(0, '-std=c99')
diff -rup a/setup/extensions.json b/setup/extensions.json
--- a/setup/extensions.json 2022-06-17 04:35:27.000000000 +0200
+++ b/setup/extensions.json 2024-07-19 11:52:11.253389395 +0200
@@ -75,7 +75,7 @@
"name": "sqlite_extension",
"headers": "calibre/utils/cpp_binding.h",
"sources": "calibre/db/sqlite_extension.cpp",
- "needs_c++14": true,
+ "needs_c++17": true,
"libraries": "icudata icui18n icuuc icuio stemmer",
"windows_libraries": "icudt icuin icuuc icuio libstemmer",
"lib_dirs": "!icu_lib_dirs",

View File

@@ -0,0 +1,33 @@
Changelog:
Only relevant if you embed the calibre server within a larger server, it
means attackers who can convince users to click on a specially crafted
link, can run JavaScript code with the same origin as the larger server
calibre is embedded in.
From e75f85919a3c3a5f2d87861050d8483d66561c06 Mon Sep 17 00:00:00 2001
From: Kovid Goyal <kovid@kovidgoyal.net>
Date: Tue, 30 Jul 2024 13:40:21 +0530
Subject: [PATCH] Fix #2075130 [Private
bug](https://bugs.launchpad.net/calibre/+bug/2075130)
---
src/calibre/srv/legacy.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/calibre/srv/legacy.py b/src/calibre/srv/legacy.py
index 055228ebee..85586b07a6 100644
--- a/src/calibre/srv/legacy.py
+++ b/src/calibre/srv/legacy.py
@@ -255,7 +255,7 @@ def browse(ctx, rd, rest):
if rest.startswith('book/'):
# implementation of https://bugs.launchpad.net/calibre/+bug/1698411
# redirect old server book URLs to new URLs
- redirect = ctx.url_for(None) + '#book_id=' + rest[5:] + "&amp;panel=book_details"
+ redirect = ctx.url_for(None) + '#book_id=' + int(rest[5:]) + "&amp;panel=book_details"
from lxml import etree as ET
return html(ctx, rd, endpoint,
E.html(E.head(
--
2.44.2

View File

@@ -0,0 +1,27 @@
diff --git a/src/calibre/utils/img.py b/src/calibre/utils/img.py
index b61627b63e..ff51c76e75 100644
--- a/src/calibre/utils/img.py
+++ b/src/calibre/utils/img.py
@@ -129,8 +129,6 @@ def image_from_data(data):
i = QImage()
if not i.loadFromData(data):
q = what(None, data)
- if q == 'jxr':
- return load_jxr_data(data)
raise NotImage(f'Not a valid image (detected type: {q})')
return i
@@ -693,13 +691,6 @@ def test(): # {{{
despeckle_image(img)
remove_borders_from_image(img)
image_to_data(img, fmt='GIF')
- p = subprocess.Popen([get_exe_path('JxrDecApp'), '-h'],
- creationflags=subprocess.DETACHED_PROCESS if iswindows else 0,
- stdout=subprocess.PIPE)
- raw, _ = p.communicate()
- p.wait()
- if b'JPEG XR Decoder Utility' not in raw:
- raise SystemExit('Failed to run JxrDecApp')
# }}}

View File

@@ -0,0 +1,38 @@
From 6d87aa054724155c9413e5692fa1f242f9cc0efc Mon Sep 17 00:00:00 2001
From: Eli Schwartz <eschwartz93@gmail.com>
Date: Fri, 23 Aug 2024 02:20:00 -0400
Subject: [PATCH] tests: delete qt TTS assert which is not yet used
It will be used in future versions of calibre, and should likely be
gated on USE=speech.
---
src/calibre/test_build.py | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py
index 4f19363680..898caad665 100644
--- a/src/calibre/test_build.py
+++ b/src/calibre/test_build.py
@@ -314,7 +314,7 @@ def test_apsw(self):
def test_qt(self):
if is_sanitized:
raise unittest.SkipTest('Skipping Qt build test as sanitizer is enabled')
- from qt.core import QApplication, QFontDatabase, QImageReader, QLoggingCategory, QNetworkAccessManager, QSslSocket, QTextToSpeech, QTimer
+ from qt.core import QApplication, QFontDatabase, QImageReader, QLoggingCategory, QNetworkAccessManager, QSslSocket, QTimer
QLoggingCategory.setFilterRules('''qt.webenginecontext.debug=true''')
if hasattr(os, 'geteuid') and os.geteuid() == 0:
# likely a container build, webengine cannot run as root with sandbox
@@ -348,10 +348,6 @@ def test_qt(self):
try:
ensure_app()
self.assertGreaterEqual(len(QFontDatabase.families()), 5, 'The QPA headless plugin is not able to locate enough system fonts via fontconfig')
- available_tts_engines = tuple(x for x in QTextToSpeech.availableEngines() if x != 'mock')
- self.assertTrue(available_tts_engines)
-
- self.assertGreaterEqual
from calibre.ebooks.oeb.transforms.rasterize import rasterize_svg
img = rasterize_svg(as_qimage=True)
self.assertFalse(img.isNull())
--
2.44.2

View File

@@ -0,0 +1,13 @@
# /etc/conf.d/calibre-server
# Change this to the user you want to run calibre-server as.
# You may specify a group too, after a colon
# NOTE: This must be set and not to root!
CALIBRE_USER=
# Set the path of the library to serve.
# Defaults to the default location for CALIBRE_USER.
#CALIBRE_LIBRARY='<user home directory>/Calibre Library'
# Extra options to pass to calibre-server.
# See the calibre-server man page for more options.
#CALIBRE_SERVER_OPTS="--userdb /srv/calibre/users.sqlite --enable-auth --worker-count 10 --port 8080"

View File

@@ -0,0 +1,58 @@
#!/sbin/openrc-run
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2 or later
depend() {
need net
need localmount
after bootmisc
}
checkconfig() {
if [ "${CALIBRE_USER}" = "" -o "${CALIBRE_USER}" = "root" ] ; then
eerror "Please edit /etc/conf.d/calibre-server"
eerror "You have to specify a user to run calibre-server as, as we will not run it as root!"
eerror "Modify CALIBRE_USER to your needs (you can also add a group, after a colon)"
return 1
fi
if ! getent passwd "${CALIBRE_USER%:*}" >/dev/null ; then
eerror "Please edit /etc/conf.d/calibre-server"
eerror "Your user has to exist!"
return 1
fi
if [ "${CALIBRE_USER%:*}" != "${CALIBRE_USER}" ] ; then
if ! getent group "${CALIBRE_USER#*:}" >/dev/null ; then
eerror "Please edit /etc/conf.d/calibre-server"
eerror "Your group has to exist too!"
return 1
fi
fi
if [ "${CALIBRE_LIBRARY}" = "" ] ; then
CALIBRE_USER_HOME=$(getent passwd "${CALIBRE_USER%:*}" | cut -d ':' -f 6)
CALIBRE_LIBRARY="${CALIBRE_USER_HOME}/Calibre Library"
fi
if [ ! -d "${CALIBRE_LIBRARY}" ] ; then
eerror "Please edit /etc/conf.d/calibre-server"
eerror "The Calibre library, '${CALIBRE_LIBRARY},' does not exist."
eerror "Please modify CALIBRE_LIBRARY to point to a valid library."
return 1
fi
return 0
}
start() {
checkconfig || return $?
local pidfile=/var/run/calibre-server.pid
ebegin "Starting calibre-server"
start-stop-daemon --user "${CALIBRE_USER}" \
--pidfile "${pidfile}" --make-pidfile --background --exec /usr/bin/calibre-server \
-- ${CALIBRE_OPTS} "${CALIBRE_LIBRARY}"
eend $?
}
stop() {
ebegin "Stopping calibre-server"
start-stop-daemon --stop --user "${CALIBRE_USER}" \
--pidfile /var/run/calibre-server.pid
eend $?
}

View File

@@ -0,0 +1,35 @@
From e9cc00560a28f56a303cca97630ab58e519dd9c8 Mon Sep 17 00:00:00 2001
From: Kovid Goyal <kovid@kovidgoyal.net>
Date: Mon, 8 Jan 2024 09:12:35 +0530
Subject: [PATCH] Fix #2048475 [Tests fail with lxml
5.0](https://bugs.launchpad.net/calibre/+bug/2048475)
---
src/calibre/utils/xml_parse.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/calibre/utils/xml_parse.py b/src/calibre/utils/xml_parse.py
index a31c6ed83ed7..339538b90057 100644
--- a/src/calibre/utils/xml_parse.py
+++ b/src/calibre/utils/xml_parse.py
@@ -36,6 +36,11 @@ def safe_xml_fromstring(string_or_bytes, recover=True):
return ans
+def unsafe_xml_fromstring(string_or_bytes):
+ parser = etree.XMLParser(resolve_entities=True)
+ return fs(string_or_bytes, parser=parser)
+
+
def find_tests():
import unittest, tempfile, os
from calibre.constants import iswindows
@@ -61,7 +66,7 @@ def t(tid, val, expected, safe=True):
raw = templ.format(id=tid, val=val)
err = None
try:
- root = safe_xml_fromstring(raw) if safe else etree.fromstring(raw)
+ root = safe_xml_fromstring(raw) if safe else unsafe_xml_fromstring(raw)
except Exception as e:
err = str(e)
root = None