elf: Ignore garbage data

With qt5-webengine 5.15.9-3 on Arch Linux, there only was a rebuild:
70aa541b4f

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)
This commit is contained in:
Florian Bruhin 2022-05-17 14:15:26 +02:00
parent 4fa602d238
commit db1382f75c
2 changed files with 18 additions and 1 deletions

View File

@ -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:

View File

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