feat(self-packaging #42): selfpath + bundle_locator (EOCD reverse scan)#61
Merged
Merged
Conversation
Part of #40, depends on #41. Two small modules that let the running binary discover an appended ZIP bundle. - `src/selfpath.{hpp,cpp}` -- cross-platform self-binary path: - Linux: readlink("/proc/self/exe") - macOS: _NSGetExecutablePath - Windows: GetModuleFileNameW (with buffer growth loop) - `src/bundle_locator.{hpp,cpp}` -- reverse-scan a file for a ZIP End-of-Central-Directory record: - reads tail buffer of 22 + max_comment + 64 KiB padding budget - reverse-scans for the 0x06054b50 signature - validates: single-disk archive, entry counts match, comment length fits in tail, anything after comment must be zero (padding tolerance), central directory must fit before EOCD - returns BundleLocation{offset, size} or nullopt - `LocateBundleInSelf()` convenience wrapper over GetSelfPath() Tests (`test/cpp/bundle_locator_test.cpp`, 7 cases): - locate a ZIP appended to 4 KiB of random leading bytes - tolerate 10 KiB of trailing zero padding (the spike-caught case) - nullopt when no EOCD signature exists in random data - nullopt when an EOCD signature has impossible cd_size / cd_offset - nullopt when the bundle is truncated by 1 KiB from EOF - selfpath returns an existing path - LocateBundleInSelf returns nullopt against the unbundled test binary Fixtures reuse `archive_io::WriteArchive` (#41) to produce real ZIPs. Closes #42.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of epic #40. Re-opening #52 after auto-close (base branch gh-41 was deleted on #51's merge).
Summary
Two small modules that together let the running binary discover whether
a ZIP archive has been appended to it.
src/selfpath.{hpp,cpp}-- cross-platform self-binary path(
/proc/self/exe/_NSGetExecutablePath/GetModuleFileNameW).src/bundle_locator.{hpp,cpp}-- reverse-scan a file for a ZIPEnd-of-Central-Directory record, returning
BundleLocation{offset, size}or
nullopt.What the locator checks
0x06054b50not present in tailThe padding tolerance is load-bearing: libarchive's default tar-block
rounding pushed the EOCD off file-EOF in the spike; reader is defensive.
Tests (7 cases / 14 assertions, all green on Linux x86_64)
Closes #42. Part of #40.