Skip to content

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
pharo-vcs:Pharo15from
takano32:fix/clone-options-stale-layout-Pharo15
Open

takano32 wants to merge 1 commit into
pharo-vcs:Pharo15from
takano32:fix/clone-options-stale-layout-Pharo15

Conversation

@takano32

Copy link
Copy Markdown

Same fix as #118 (which targets the Pharo13 branch 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>>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 memcpys 416 bytes into a 408-byte buffer → 8-byte heap-buffer overflow on every clone-options init (it lands on the neighbouring chunk's prev_size, so it detonates later at an unrelated allocation — hence the nondeterministic crashes).

On this branch initializeStructures is just the four alias assignments — there is no rebuild at all — so LGitCloneOptions is never corrected after the adaptive members change.

Fix

LGitExternalStructure allSubclasses do: [ :each | each rebuildFieldAccessors ]

Rebuild every LibGit structure after aliasing, so any composite tracks the current adaptive members. Idempotent; initializeStructures runs at startup.

Verification

Runtime-verified on the Pharo13 branch (see #118), on libgit2 1.9.7 / aarch64 / glibc 2.43: LGitCloneOptions byteSize goes 408 → 416 (matching native sizeof(git_clone_options)), and a 512-byte sentinel buffer passed to initializeWithDefaults is 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 the LastLibgitVersion guard that Pharo13 has, to skip the rebuild when the version is unchanged).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Dszsb5ALkx1ytH8atZPvEV

…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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant