Repository navigation
Rebuild structs embedding version-adaptive structs on libgit2 >= 1.9 (fixes git_clone_options heap overflow) - #120
Open
takano32 wants to merge 1 commit into
Conversation
…options heap overflow on libgit2 >= 1.9) initializeStructures re-aliases the four version-adaptive structs but never rebuilds a structure that embeds one by value. LGitCloneOptions embeds LGitFetchOptions; on libgit2 >= 1.9 git_remote_callbacks grew an update_refs field (120 -> 128), dragging git_fetch_options 208 -> 216 and git_clone_options 408 -> 416. The cached LGitCloneOptions layout stays 408, so git_clone_init_options memcpy's 416 bytes into a 408-byte buffer -> heap overflow on every clone. Rebuild every LibGit structure after aliasing so composites track the current adaptive members. The same fix is verified at runtime on the Pharo13 branch (byteSize 408 -> 416 on libgit2 1.9.7, sentinel confirms no overflow). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dszsb5ALkx1ytH8atZPvEV
This branch has not been deployed
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.
Same fix as #118 (which targets the
Pharo13branch and is verified there at runtime), applied to this branch, which has the identical defect.Problem
On a host whose system libgit2 is 1.9.x, the bindings corrupt the glibc heap on any clone.
LGitLibrary>>initializeStructuresre-aliases the four version-adaptive structs but never rebuilds a structure that embeds one by value.LGitCloneOptionsembedsLGitFetchOptions; on libgit2 ≥ 1.9git_remote_callbacksgrew anupdate_refsfield (120→128), dragginggit_fetch_options208→216 andgit_clone_options408→416. The cachedLGitCloneOptionslayout stays 408, sogit_clone_init_optionsmemcpys 416 bytes into a 408-byte buffer → 8-byte heap-buffer overflow on every clone-options init (it lands on the neighbouring chunk'sprev_size, so it detonates later at an unrelated allocation — hence the nondeterministic crashes).On this branch
initializeStructuresis just the four alias assignments — there is no rebuild at all — soLGitCloneOptionsis never corrected after the adaptive members change.Fix
Rebuild every LibGit structure after aliasing, so any composite tracks the current adaptive members. Idempotent;
initializeStructuresruns at startup.Verification
Runtime-verified on the Pharo13 branch (see #118), on libgit2 1.9.7 / aarch64 / glibc 2.43:
LGitCloneOptions byteSizegoes 408 → 416 (matching nativesizeof(git_clone_options)), and a 512-byte sentinel buffer passed toinitializeWithDefaultsis then modified only through byte 416 (== byteSize) — no overflow.Not runtime-tested on this branch specifically (I don't have an image on this Pharo line to load), but the defect and the fix are structurally identical — same non-adaptive
LGitCloneOptions, same missing rebuild. Happy to adjust if you'd prefer a different shape here (e.g. adding theLastLibgitVersionguard thatPharo13has, to skip the rebuild when the version is unchanged).🤖 Generated with Claude Code
https://claude.ai/code/session_01Dszsb5ALkx1ytH8atZPvEV