fix(installer): interactive fallback rejects an install root without its python suffix

Offen Anfängerfreundlich
#8,714 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 2 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
78/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python

Rechercherichtung

Lies scripts/install_api.py im Bereich des interaktiven Fallbacks in den Zeilen 124–136 und führe dann den bereitgestellten synthetischen Harness für root-then-python, python-only und adjacent-valid aus. Das Issue benennt den verlorenen zusammengefügten Pfad und gibt die erwarteten .pth-Ziele und die Anzahl der Eingabeaufforderungen an; die Aufgabe ist abgeschlossen, wenn eine Root-Antwort nach einer Eingabeaufforderung erfolgreich ist und beide Kontrollen ihre Ergebnisse beibehalten.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Summary

When the installer cannot import from its existing adjacent python directory and prompts for another Binary Ninja install directory, entering an alternate install root leaves the path unchanged. The next validation checks the root instead of its python child and prompts again. Entering the child's full path works in the bounded fixture below. This affects the interactive recovery branch; a working adjacent API directory bypasses it.

Steps to reproduce

The following executed reproduction uses the unmodified installer source with synthetic install directories and a stub binaryninja module. It exercises the command-line entry point, directory guard, real validate_path, prompt loop, and .pth writing. It does not import a Binary Ninja native core or reproduce a licensed Binary Ninja installation.

  1. Save the Python harness below as reproduce.py outside an installation. Supply the path to the installer source from either baseline listed under Runtime or environment; the harness copies it into a synthetic installation layout before execution.
  2. Run python3 -I -S reproduce.py SOURCE_INSTALL_API root-then-python. The initial original/python directory exists but is empty, so validation fails with ModuleNotFoundError. The alternate installation has a stub module only under alternate/python. The first answer is the absolute alternate install root; the second is its python child.
  3. Run the python-only control with the same command, replacing the final argument. It supplies the child immediately. Run the adjacent-valid control to put the stub under the original adjacent Python directory and avoid fallback entirely.
"""Exercise the unmodified installer with synthetic packages, never a native core.

Usage: python3 -I -S reproduce.py SOURCE_INSTALL_API CASE
CASE: root-then-python, python-only, adjacent-valid
"""
import builtins
import contextlib
import io
import json
from pathlib import Path
import runpy
import shutil
import site
import sys
import tempfile

source = Path(sys.argv[1]).resolve()
case = sys.argv[2]
assert case in {"root-then-python", "python-only", "adjacent-valid"}
with tempfile.TemporaryDirectory(prefix="installer-fixture-") as directory:
    fixture = Path(directory)
    original = fixture / "original"
    alternate = fixture / "alternate"
    destination = fixture / "site-packages"
    (original / "scripts").mkdir(parents=True)
    (original / "python").mkdir()
    (alternate / "python").mkdir(parents=True)
    destination.mkdir()
    script = original / "scripts" / "install_api.py"
    shutil.copyfile(source, script)
    module = "def core_version():\n    return 'synthetic-core-no-native-runtime'\n"
    (alternate / "python" / "binaryninja.py").write_text(module)
    if case == "adjacent-valid":
        (original / "python" / "binaryninja.py").write_text(module)
    answers = iter({
        "root-then-python": [alternate, alternate / "python"],
        "python-only": [alternate / "python"],
        "adjacent-valid": [],
    }[case])
    prompts = []

    def answer(prompt):
        prompts.append(prompt)
        print(prompt)
        try:
            value = str(next(answers))
        except StopIteration:
            raise AssertionError("unexpected extra installer prompt")
        print(value)
        return value

    builtins.input = answer
    site.getusersitepackages = lambda: str(destination)
    site.getsitepackages = lambda: [str(destination)]
    site.check_enableusersite = lambda: True
    sys.argv = [str(script)]
    output = io.StringIO()
    with contextlib.redirect_stdout(output), contextlib.redirect_stderr(output):
        runpy.run_path(str(script), run_name="__main__")
    pth_lines = (destination / "binaryninja.pth").read_text().splitlines()
    expected = original / "python" if case == "adjacent-valid" else alternate / "python"
    assert pth_lines == [str(expected), str(expected) + str(sys.version_info.major)]
    assert len(prompts) == {"root-then-python": 2, "python-only": 1, "adjacent-valid": 0}[case]
    log = output.getvalue().replace(str(fixture), "<fixture>")
    print(log, end="")
    print(json.dumps({"case": case, "prompts": len(prompts), "pth_target": str(expected.relative_to(fixture)), "success": True}))

The harness redirects every site-packages destination into its temporary directory, and -I -S excludes existing site initialization and environment-provided import paths. It normalizes its temporary root to <fixture> in printed output. The stub returns a deliberately synthetic version string; it implements only the interface this installer validates.

Expected behavior

After reaching the interactive fallback, supplying an install root whose python child passes validation should select that child and finish without another path prompt. The prompt explicitly asks for the install directory, and the non-python branch attempts to append python. Supplying the child explicitly should continue to work, and an already valid adjacent Python directory should continue to bypass the fallback.

Actual behavior

The root-then-child case produced this result on both source baselines:

Found install folder of <fixture>/original/python
Binary Ninja not found: <fixture>/original/python
Please provide the path to Binary Ninja's install directory:
 [<fixture>/original/python] :
<fixture>/alternate
Binary Ninja not found: <fixture>/alternate
Please provide the path to Binary Ninja's install directory:
 [<fixture>/alternate] :
<fixture>/alternate/python
Found Binary Ninja core version: synthetic-core-no-native-runtime
Installing on user site: <fixture>/site-packages
Binary Ninja API installation success.
{"case": "root-then-python", "prompts": 2, "pth_target": "alternate/python", "success": true}

The development-source python-only control completed with one prompt and wrote both .pth entries pointing to the alternate Python directory and its Python-major-version companion. The adjacent-valid control completed with zero prompts and wrote the entries for the original Python directory. Two local runs of each reported case produced the same results. No runtime result for a real licensed installation is claimed.

Evidence

  • Expected source: The pinned installer's prompt at scripts/install_api.py:124 asks for the install directory; its branch at lines 133–136 attempts to handle an answer without a python suffix. The earlier implementation visible in the refactoring PR under References assigned the joined path.
  • Failure source: The pinned installer at scripts/install_api.py:133–136 discards the return value of os.path.join(new_path, "python") before assigning api_path = new_path; the executed fixture transcript above shows the resulting second prompt.
  • Evidence provenance: observed
  • Local verification: reproduced
  • Reproduction completeness: incomplete
  • Missing fact: An end-to-end run using licensed Binary Ninja installations, including an existing adjacent API directory that fails import and an alternate installation whose API can import in the same interpreter, was not performed. The fixture supplies those import conditions synthetically.

Restoration check

With the same fixture and initially failing adjacent directory, the root answer should complete installation after one prompt and write .pth entries for the alternate python directory, rather than validate the root and ask again. The explicit-child and valid-adjacent controls should retain their successful results. These signals test the same input contract without bypassing path validation.

Runtime or environment

Version and Platform (required):

  • Binary Ninja version: latest published stable source stable/6.0.10905, pinned installer; current default-branch dev source, pinned installer. The installer files are byte-identical.
  • Edition: not applicable to the synthetic fixture; no licensed native runtime was used.
  • OS: macOS.
  • OS version: 27.2.
  • CPU architecture: arm64.
  • Python: CPython 3.15.2, launched with -I -S.

No analysis binary, screenshot, or video is needed for this installer-only fixture. A missing initial adjacent directory does not reach the prompt: the earlier isdir guard returns first. The reproduction creates that directory deliberately and does not run the installer directly from a source checkout as though it were an installed product.

References

  • Closed issue #5811 concerns running the script from a source clone and was resolved by directing the reporter to the installed copy. This report exercises the installed-layout fallback with an existing adjacent directory; it does not claim that a clone is a supported installation or that Free provides licensed API access.
  • Merged refactoring PR #3809 contains the earlier joined-path assignment and the refactored fallback. Its virtual-environment problem is distinct from the root-answer normalization reported here.

Triage assessment

  • Impact level: P2
  • Assessment status: supported
  • Impact basis: The executed fixture demonstrates a bounded failure of the interactive recovery input contract: an install root is rejected while its API child succeeds. The usual working adjacent path is unaffected in the control. Frequency in real licensed installations is unknown.
  • Workaround status: available
  • Workaround basis: Supplying the explicit python child succeeds and writes the expected .pth entries in the same fixture. Its use with a real installation still requires that installation's API to import successfully in the selected interpreter.
Vorherrschende Sprache
C++
Sterne
1.3k
Forks
304
Ø Merge
2 T. 20 Std.
Gemergte PRs (30 T.)
10

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus Vector35/binaryninja-api

Alle Issues in Vector35/binaryninja-api

Ähnliche Issues

Weitere Issues zu C++

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.