Summary
A bounds-validation flaw in libgit2 can cause a Git client to read beyond the end of a smart-protocol packet while processing a server's refs advertisement. A malicious Git server may exploit this condition to crash clients that connect over HTTP, HTTPS, SSH, or the Git protocol.
Affected context
The vulnerability occurs in libgit2 clients that process smart-protocol pkt-line capability data from an untrusted Git server. It becomes risky when the capability buffer is shorter than the parser assumes and packet-boundary checks are not performed before fixed-size comparisons and subsequent length calculations.
Exploit preconditions
- Attack surface: Git transport protocol handling in applications linked
against libgit2
- Required access: Ability to operate or control a Git server that the
target client contacts
- Trigger point: Processing the first refs-advertisement packet - Why exploitation is possible: A malformed capability field can cause a
fixed-size comparison to read past the packet, followed by an underflowed
length calculation and an out-of-bounds heap walk
Why this happens
The parser performs a fixed-size string comparison without first confirming that the pkt-line contains enough bytes for that operation. When a server-provided capability value is truncated or positioned at a packet boundary, pointer advancement can move beyond the valid buffer. A later length calculation may underflow, allowing a memory-search operation to traverse outside the allocated object. This behavior maps primarily to CWE-125, Out-of-Bounds Read, and is also related to improper input validation and incorrect buffer-length handling.
Potential impact
- A malicious server may crash a connected Git client
- Applications could experience denial of service during repository access
- Repeated connections could cause service instability
- Memory-safety failures could expose additional risk if combined with other bugs
General mitigation guidance
Mitigation generally focuses on ensuring every parser operation is bounded by the actual pkt-line length. Defensive patterns include validating packet sizes before fixed-width comparisons, using overflow- and underflow-safe length arithmetic, rejecting malformed capability advertisements, and centralizing checked buffer-access helpers. Applications should use maintained libgit2 releases that contain the parser correction, reduce trust in remote protocol data, and run Git operations with least privilege and suitable process isolation where practical.
How teams detect issues like this
Detection can include static analysis for fixed-size reads that lack prior length checks, arithmetic on attacker-controlled buffer lengths, and memchr-like calls whose bounds derive from unchecked subtraction. Code review should examine packet-parser state transitions, pointer advancement, and integer overflow or underflow handling. Fuzzing smart-protocol refs-advertisement packets and enforcing memory-safety testing in CI can help identify malformed-input crashes. Automated security review tools may also flag unchecked buffer boundaries and suspicious length calculations.

