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']),