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

Đang mở Phù hợp với người mới
#8,714 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
cli, developer-experience

Hướng nghiên cứu

Đọc scripts/install_api.py ở phần fallback tương tác tại các dòng 124–136, sau đó chạy harness tổng hợp được cung cấp cho root-then-python, python-only và adjacent-valid. Issue xác định đường dẫn đã nối bị mất và nêu các đích .pth cùng số lần nhắc dự kiến; hoàn tất khi câu trả lời root thành công sau một lần nhắc và cả hai trường hợp đối chứng vẫn giữ nguyên kết quả.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
C++
Star
1.3k
Fork
304
Merge trung bình
2 ngày 20 giờ
Pull request đã merge (30 ngày)
10

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Vector35/binaryninja-api

Tất cả issue của Vector35/binaryninja-api

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.