Commit Graph

16262 Commits

Author SHA1 Message Date
Edward Thomson
200aace53d Merge pull request #7165 from ambv/tcp-keepalive
fix: prevent SSH timeout infinite loop and enable TCP keepalive
2026-05-02 14:12:25 +01:00
Edward Thomson
16cb9c5ed8 Merge pull request #7239 from libgit2/ethomson/mergefix
merge_files: avoid UB in xdiff
2026-05-02 08:44:05 +01:00
Edward Thomson
a7b267c7a6 Merge pull request #7238 from kanru-contrib/null-terminate-pack-buffer
fix(pack): ensure pack_backend__read returns null terminated buffer
2026-05-02 08:33:47 +01:00
Edward Thomson
43b5707765 Merge pull request #7241 from kcsaul/fix/cmake-temp-header
cmake: write git.h.tmp to current binary directory
2026-05-02 08:27:13 +01:00
Edward Thomson
a25d9a18fa xdiff: don't try to malloc 0 bytes
For zero byte files, avoid allocation - this avoids undefined behavior
around malloc(0) and potentially memcpy(..., NULL, 0).
2026-05-02 08:24:18 +01:00
Edward Thomson
643b7e1038 merge_files: some simplification 2026-05-02 08:24:18 +01:00
Edward Thomson
8d4d980b10 merge_files: test with zero-byte file
Test handing a zero byte but extant file to merge_files.
2026-05-02 08:24:18 +01:00
Kevin Saul
5b59e4a180 cmake: write git.h.tmp to current binary directory 2026-05-02 13:56:47 +12:00
Kan-Ru Chen
22e80c6065 fix(pack): ensure pack_backend__read returns null terminated buffer
Depending on the zlib library used, the inflate() function may write
beyond the object size into the additional trailing buffer for aligned
memory copies. This may cause out-of-bounds memory read if the object
buffer is later used without checking the object size, as in
git_commit__extract_signature.

Link: https://github.com/zlib-ng/zlib-ng/issues/1767
Signed-off-by: Kan-Ru Chen <kanru@kanru.info>
2026-05-01 07:47:54 +09:00
Edward Thomson
cefc409a97 Merge pull request #7092 from eantoranz/git_merge_file_from_index-null_child
git_merge_file_from_index: handle cases when a child (ours or theirs) is null
2026-04-30 23:39:06 +01:00
Edward Thomson
70ff46d7fe Merge pull request #7236 from libgit2/ethomson/lengths
Check object lengths against headers in `read_loose`
2026-04-30 23:19:07 +01:00
Edward Thomson
a1c807c79e object: test looking up truncated objects
Add a test that looks up an invalid, truncated object, that is shorter
than the advertised length.
2026-04-30 22:59:20 +01:00
Edward Thomson
249b9d6aad Merge pull request #7234 from libgit2/ethomson/cmake
cmake: don't recreate git2.h unnecessarily
2026-04-29 21:33:08 +01:00
Edward Thomson
d5241a2c04 cmake: don't recreate git2.h unnecessarily
Instead of regenerating `git2.h` on every cmake invocation, use
`configure_file` to avoid rewriting it. This keeps timestamps inline and
avoids unnecessarily rebuilding the library.
2026-04-29 20:56:29 +01:00
Edward Thomson
56883f9e9d Merge pull request #7232 from kcsaul/fix/config-memory-backend
Config Memory Backend Corruption Fix
2026-04-29 20:34:40 +01:00
Edward Thomson
445193c4f8 Merge pull request #7118 from oliverchang/fix
Fixed a heap-buffer-overflow in the smart_pkt.c:set_data function.
2026-04-29 20:15:04 +01:00
Edward Thomson
81706d1b35 Merge pull request #7231 from libgit2/ethomson/worktree_fi
repository: fix operators in `foreach_worktree`
2026-04-29 15:25:34 +01:00
Kevin Saul
d30a69c63d config: fix crash after memory backend entry freed 2026-04-29 22:24:33 +12:00
Kevin Saul
3b5ecb0d42 config: update memory backend test to reproduce crash 2026-04-29 22:11:28 +12:00
Edward Thomson
c0a4ef05f4 repository: fix operators in foreach_worktree
Fix a simple operator precedence bug in
`git_repository_foreach_worktree`.
2026-04-29 09:44:05 +01:00
Edward Thomson
c16683f5fb Merge pull request #7230 from libgit2/ethomson/clar-2
clar: update with const correct iterator
2026-04-28 21:14:38 +01:00
Edward Thomson
124a1a801b clar: update with const correct iterator 2026-04-28 15:25:58 +01:00
Edward Thomson
1e7d7c07d0 Merge pull request #7195 from weihanglo/insteadof
fix: apply insteadOf from global config for detached remotes
2026-04-24 11:19:47 +01:00
Edward Thomson
8a1f012861 Merge pull request #7229 from weihanglo/fix
fix(transport): get oid_type on local transport
2026-04-24 11:14:02 +01:00
Weihang Lo
e047e80074 fix(transport): get oid_type on local transport
Cache `oid_type` in `transport_local` struct during `connect()`
so `git_remote_oid_type()` keeps working after disconnect.

This matches the smart transport behavior.
2026-04-23 23:17:57 -04:00
Weihang Lo
6753d535c8 test(transport): get oid_type on local transport
Exercise git_remote_oid_type on a SHA256 local transport.

The after-disconnect assertion is commented out because
local_oid_type dereferences `t->repo`, which local_close
has already freed (SIGSEGV).

I ran these commands to test btw:

```
cmake .. -DGIT_EXPERIMENTAL_SHA256=ON -DBUILD_TESTS=ON
cmake --build .
./libgit2_tests -snetwork::remote::local::sha256_oid_type
```
2026-04-23 23:14:01 -04:00
Weihang Lo
d375ab70c1 fix(remote): apply insteadOf from global config for detached remotes
Detached remotes already read global/system config for http proxy
settings, but did not apply url.*.insteadOf or url.*.pushInsteadOf
rules. This inconsistency meant that `git_remote_create_detached`
behaved differently from git's `ls-remote`, which was the primary
use case for detached remotes.

This fixes it by loading the default config when no repository is
provided and apply insteadOf rules consistently.

While this is a behavior change, it still respects
`GIT_REMOTE_CREATE_SKIP_INSTEADOF`, meaning that user can restore
the previous behavior with minimal effort

Fixes https://github.com/libgit2/libgit2/issues/5469
2026-04-23 18:32:11 -04:00
Weihang Lo
aa5d9886d1 test(remote): show buggy detached remote insteadOf behavior
`git_remote_create_detached` does not apply
`url.*.insteadOf` or url.*.pushInsteadOf from global config.

These tests currently pass, asserting the buggy behavior
and serving as a minimal reproduction.

The assertions will be updated when the fix is applied.

See <https://github.com/libgit2/libgit2/issues/5469>
2026-04-23 18:32:11 -04:00
Edward Thomson
d35f378794 Merge pull request #7226 from weihanglo/local-object-format
fix(clone): propagate object format in local clone
2026-04-23 22:11:06 +01:00
Edward Thomson
08d91d0fbf Merge pull request #7228 from DanielEScherzer/patch-1
`GIT_REMOTE_DOWNLOAD_TAGS_ALL`: remove stray "the" in docs
2026-04-23 21:37:16 +01:00
Edward Thomson
9fd0be8525 Merge pull request #7227 from weihanglo/pseudoref
fix(refs): attach refdb owner to loose pseudorefs
2026-04-23 21:36:50 +01:00
Edward Thomson
b7e3a7df51 Merge pull request #7225 from csware/nullptr-deref
repo: Fix possible null pointer dereference
2026-04-23 21:31:09 +01:00
Edward Thomson
87c03c1aaa Apply suggestions from code review
Co-authored-by: Edward Thomson <ethomson@edwardthomson.com>
2026-04-23 21:30:21 +01:00
Daniel Scherzer
9e78ec20bb GIT_REMOTE_DOWNLOAD_TAGS_ALL: remove stray "the" in docs 2026-04-22 16:27:54 -07:00
Weihang Lo
7a9b284302 fix(refdb): check loose ref allocation failures
The loose ref lookup helper was exposed by 7f35dc581
and then used by b17ecb23e directly for pseudoref lookup.

While investigating the pseudoref owner regression,
I found that the helper also returns success
with a NULL output reference when `git_reference__alloc()`
or `git_reference__alloc_symbolic()` failed.

This fixes it by reporting allocation failures inside
`git_reference__lookup_loose`.
2026-04-22 17:51:25 -04:00
Weihang Lo
735bb2e2f5 fix(refs): attach refdb owner to loose pseudorefs
Pseudoref lookup now reads `FETCH_HEAD` directly as a loose ref,
but callers still expect looked-up references to know their owning
repository.

Attach the repo's refdb after the loose pseudoref is read so
owner-dependent ops such as peeling can safely resolve objects.
2026-04-22 17:50:23 -04:00
Weihang Lo
c0a5341635 test(refs): cover pseudoref owner regression from b17ecb23e
b17ecb23e changed pseudoref lookup to read loose refs directly,
bypassing refdb lookup.

This documents the resulting buggy behavior:
a looked-up `FETCH_HEAD` pseudoref has no owning refdb attached.
2026-04-22 17:50:14 -04:00
Weihang Lo
47fdc9c3f0 fix(clone): propagate object format in local clone
`clone_local_into()` copies objects from the source repository
but does not set the destination's object format.
This cause SHA256 repositories to be unreadable after a local clone
because the destination defaults to SHA1.

The remote clone path already handles this correctly
so local clone path follows suite.

See: <https://github.com/libgit2/libgit2/blob/1f34e2a57/src/libgit2/clone.c#L448-L450>
2026-04-19 11:34:50 -04:00
Weihang Lo
9fa192de95 test(clone): document SHA256 local clone failure
Local clone, both hardlink and copy paths, does not propagate
the source repository's object format to the destination.

A SHA256 repository cloned locally is initialized as SHA1
and caused object lookup failures.

These tests are added as reproducible examples,
and will be fixed in the next commit

* `sha256_via_no_local`
  * `file://` URL + `GIT_CLONE_NO_LOCAL` -> remote code path
* `sha256_object_format_is_propagated`
  * `file://` URL + `GIT_CLONE_LOCAL` -> local code path with hardlinks
* `sha256_no_links_object_format_is_propagated`
  * `file://` URL + `GIT_CLONE_LOCAL_NO_LINKS` -> local code path with copy
2026-04-19 11:34:44 -04:00
Sven Strickroth
0bbc49b9e3 repo: Fix possible null pointer dereference
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2026-04-16 19:42:46 +02:00
Patrick Steinhardt
035634f882 github: wire up reftable tests
Wire up three new CI jobs that exercise libgit2 with the reftable
backend.
2026-04-16 14:56:46 +02:00
Patrick Steinhardt
5c6cba5142 tests: wire up reftable tests
Wire up reftable tests so that they can be executed by setting the
`CLAR_REF_FORMAT` environment variable. This only catches tests that use
`cl_git_sandbox_init()`, but that should cover most of our tests. So
this infrastructure isn't perfect, but for now it's good enough. We may
want to iterate on it in the future.
2026-04-16 14:56:46 +02:00
Patrick Steinhardt
415f3fbdb0 tests: generate test resources for reftables
Generate test resources for reftables. These resources are basically the
Git repositories we already have, but converted to use the "reftable"
format. For most of the part, this conversion is done by executing `git
refs migrate`.

A couple notes:

  - This require a recent Git upstream version with not-yet-upstreamed
    patches due to a bug in `git refs migrate` with reflogs.

  - The migration command does not yet support repositories with
    worktrees. Those were converted by first removing the worktrees,
    migrating the refs and then recreating them.

  - The HEAD_TRACKER reference in testrepo.git is not recognized as a
    root ref and is thus not automatically migrated.

  - testrepo.git has an empty reflog for refs/heads/with-empty-log that
    does not get migrated.
2026-04-16 14:56:46 +02:00
Patrick Steinhardt
ee0972cac8 refdb: wire up "reftable" storage format
Wire up the "reftable" storage format via the newly implemented reftable
backend.
2026-04-16 14:56:46 +02:00
Patrick Steinhardt
6701e02f1c refdb: implement reftable backend
Implement the reftable backend that is used to read and write reftables.
The backend is not yet used anywhere after this commit.
2026-04-16 14:56:46 +02:00
Patrick Steinhardt
61c7ff026b refs: provide git_reference__is_per_worktree_ref()
Extract the function `is_per_worktree_ref()` from the "files" backend
and expose it via "refs.h". This function will be reused by the
"reftable" backend.
2026-04-16 14:56:46 +02:00
Patrick Steinhardt
641a43c90d deps/reftable: wire up library with CMake
Wire up the reftable library with CMake. At the current point in time
the library is not yet plugged into libgit2 itself.
2026-04-16 14:56:46 +02:00
Patrick Steinhardt
9e3b00acfb deps/reftable: implement system compatibility code
While the reftable library is mostly decoupled from the Git codebase,
some specific functionality intentionally taps into Git subsystems. To
make porting of the reftable library easier all of these are contained
in "system.h" and "system.c".

Reimplement those compatibility shims so that they work for libgit2.
2026-04-16 14:56:46 +02:00
Patrick Steinhardt
623a3783bb deps: import reftable library
Import the reftable library from commit 4fee6ff3b2 (Merge branch
'ps/reftable-portability', 2026-04-08). This is an exact copy of the
reftable library.

The library will be wired into libgit2 over the next couple of commits.
2026-04-09 06:48:35 +02:00
Patrick Steinhardt
a7ab02aefc util/git2_util.h: expose GIT_INLINE_KEYWORD macro
In our util headers we expose the `GIT_INLINE()` macro to declare a
function as inline, but we don't provide a way to access the keyword
directly.

Expose a new `GIT_INLINE_KEYWORD` to fill this gap. This define will be
used in a subsequent commit.
2026-04-02 08:42:10 +02:00