Skip to content

Self-packaging #2: selfpath + bundle_locator (cross-platform EOCD scan) #42

Closed

Description

@jrosskopf

Part of epic #40. Depends on #1 (libarchive integration).

Goal

Detect whether the running binary has a ZIP archive appended at its
tail. Two small modules:

  • src/selfpath.{hpp,cpp} — cross-platform self-binary path
    resolution.
  • src/bundle_locator.{hpp,cpp} — reverse-scan for the ZIP EOCD
    signature (0x06054b50) from EOF; return offset+size or
    "no bundle".

Scope

  • selfpath:
    • Linux: readlink("/proc/self/exe")
    • macOS: _NSGetExecutablePath()
    • Windows: GetModuleFileNameW()
  • bundle_locator:
    • Open selfpath() as binary read.
    • Reverse-scan up to 64 KiB + comment-length bound for EOCD.
    • Tolerate trailing zero padding (spike lesson).
    • Validate the EOCD record fields before trusting them.
    • Return std::optional<BundleLocation{offset, size}>.

Red tests (test/cpp/bundle_locator_test.cpp, Catch2)

  1. Synthesised fixture: random leading bytes + valid ZIP appended →
    correctly located.
    • 10240 bytes of trailing zeros → still located (the spike-caught
      case).
  2. Random bytes with no EOCD signature anywhere → returns nullopt.
  3. EOCD signature present but record fields malformed → nullopt,
    no crash.
  4. 1 KiB trailing-truncated fixture → nullopt (this is spike
    behaviour Swagger UI is not functional when the endpoint is not localhost #7 — the fallback safety net).

Green criteria

  • All five red tests pass.
  • selfpath() returns the expected path on each platform we can
    unit-test (Linux/macOS in CI; Windows behaviour smoke-tested via
    the existing Windows CI leg).

Files

  • New: src/selfpath.hpp/.cpp, src/bundle_locator.hpp/.cpp,
    test/cpp/bundle_locator_test.cpp

Notes

Activity

  1. added
    enhancement
    on May 21, 2026
  2. added a commit that references this issue on May 22, 2026
    6ba63b6
  3. added 3 commits that reference this issue on May 22, 2026
    b323fe9
    b2be88e
    1b3a599
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions