summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2022-05-17 14:15:26 +0200
committerFlorian Bruhin <me@the-compiler.org>2022-05-19 08:56:16 +0200
commitdb1382f75c975ea94ad962444cc0e536a963cb81 (patch)
treedf6b07f9bf8642682cf7bc5a6048b6dc9fa4538a
parent4fa602d2383596a169d18360b7ff270de82a6b98 (diff)
downloadqutebrowser-db1382f75c975ea94ad962444cc0e536a963cb81.tar.gz
qutebrowser-db1382f75c975ea94ad962444cc0e536a963cb81.zip
elf: Ignore garbage data
With qt5-webengine 5.15.9-3 on Arch Linux, there only was a rebuild: https://github.com/archlinux/svntogit-packages/commit/70aa541b4f339a4f585a618c6d5603159fafa5a4 but somehow, we now have some kind of garbage data in the .data section: ... \x00QtWebEngine/5.15.9 Chrome/87.0.4xternalclearkey \x00ernalclearkey.diy.differentguid \x00Portable Documen/usr/src/debug/qtwebengine/src/core/net/proxying_restricted_cookie_manager_qt.cpp \x00 ... the *actual* string table only seems to follow much later: ... \x00display \x00\x00dispatchCallbackOnIOThread \x00/Cache \x00DownloadInterruptReason \x00General network failure \x00The server has gone down \x00General server failure \x00Unexpected server response \x00Download canceled by the user \x00shutdownOnUIThread \x00qrc:// \x00RequestQuotaPermission \x00\x00\x00\x00/usr/src/debug/qtwebengine/src/core/quota_permission_context_qt.cpp \x00\x00\x00\x00\x00QtWebEngine/5.15.9 Chrome/87.0.4280.144 \x00 - %04d-%02d-%02dT%0" ... So let's include the NUL bytes in our regex, to make sure we get the full variant, not the garbage. (cherry picked from commit 511df8af21ed18a65c49881175814efa72329754)
-rw-r--r--qutebrowser/misc/elf.py2
-rw-r--r--tests/unit/misc/test_elf.py17
2 files changed, 18 insertions, 1 deletions
diff --git a/qutebrowser/misc/elf.py b/qutebrowser/misc/elf.py
index bf824880a..8fadbcffd 100644
--- a/qutebrowser/misc/elf.py
+++ b/qutebrowser/misc/elf.py
@@ -270,7 +270,7 @@ def _find_versions(data: bytes) -> Versions:
correctly: https://github.com/python/typeshed/issues/1467
"""
match = re.search(
- br'QtWebEngine/([0-9.]+) Chrome/([0-9.]+)',
+ br'\x00QtWebEngine/([0-9.]+) Chrome/([0-9.]+)\x00',
data,
)
if match is None:
diff --git a/tests/unit/misc/test_elf.py b/tests/unit/misc/test_elf.py
index 86060bbde..7d3248da2 100644
--- a/tests/unit/misc/test_elf.py
+++ b/tests/unit/misc/test_elf.py
@@ -75,6 +75,23 @@ def test_result(qapp, caplog):
assert ua.upstream_browser_version == versions.chromium
+@pytest.mark.parametrize("data, expected", [
+ # Simple match
+ (
+ b"\x00QtWebEngine/5.15.9 Chrome/87.0.4280.144\x00",
+ elf.Versions("5.15.9", "87.0.4280.144"),
+ ),
+ # Ignoring garbage string-like data
+ (
+ b"\x00QtWebEngine/5.15.9 Chrome/87.0.4xternalclearkey\x00\x00"
+ b"QtWebEngine/5.15.9 Chrome/87.0.4280.144\x00",
+ elf.Versions("5.15.9", "87.0.4280.144"),
+ ),
+])
+def test_find_versions(data, expected):
+ assert elf._find_versions(data) == expected
+
+
@hypothesis.given(data=hst.builds(
lambda *a: b''.join(a),
hst.sampled_from([b'', b'\x7fELF', b'\x7fELF\x02\x01\x01']),