16015 Commits

Author SHA1 Message Date
Edward Thomson
1affb8b193 Final final v1.9.3 updates (#7250) v1.9.3 2026-05-04 22:25:59 +01:00
Edward Thomson
13458671f3 Merge pull request #7242 from libgit2/ethomson/v1.9.3 2026-05-02 09:14:46 +01:00
Edward Thomson
397548d94f v1.9.3: update changelog 2026-05-02 08:55:40 +01:00
Edward Thomson
1803dfa284 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:55:40 +01:00
Edward Thomson
047da6a2ca merge_files: some simplification 2026-05-02 08:55:40 +01:00
Edward Thomson
244d6fd827 merge_files: test with zero-byte file
Test handing a zero byte but extant file to merge_files.
2026-05-02 08:55:40 +01:00
Edmundo Carmona Antoranz
e97c067038 merge_file.c - allow ours or theirs to be NULL in git_merge_file_from_index
Improve git_merge_file_from_index by adding suport to missing children.
2026-05-02 08:55:40 +01:00
Edmundo Carmona Antoranz
b93afbc48f merge.h - improve handling when there is no ancestor in merge_file__best_path
In cases when a path is missing from the ancestor and only of the two
children is defined (IOW, the object is added), then the path in the child
that is defined should be returned.

However, merge_file__best_path is only returning a path in cases when there
is no ancestor path only if both children are defined and they match each
other.

Improve merge_file__best_path by handling the case when it is present in
only one of the children paths returning this value.
2026-05-02 08:55:40 +01:00
Edmundo Carmona Antoranz
0bd182129f git_merge_file_from_index: add unit test for deleted/added file 2026-05-02 08:55:40 +01:00
Kevin Saul
84de50665b cmake: write git.h.tmp to current binary directory 2026-05-02 08:50:34 +01:00
Kan-Ru Chen
e2d2a04487 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-02 08:50:34 +01:00
Edward Thomson
927d919e23 Merge pull request #7233 from libgit2/ethomson/v1.9.3
v1.9.3
2026-04-30 23:48:51 +01:00
Edward Thomson
378d62d278 v1.9.3: update changelog 2026-04-30 23:28:37 +01:00
Edward Thomson
4ff809dd02 v1.9.3: update version numbers 2026-04-30 23:28:37 +01:00
Edward Thomson
45eb06c4d8 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 23:28:37 +01:00
Rasheeq Azad
133597404b Check object lengths against headers in read_loose
Avoid a buffer overrun when an object's header specifies a short length
but the body is longer (fix #7177). Take care to preserve the behavior
that too-short object bodies are not an error but get zero-padded.
2026-04-30 23:23:26 +01:00
Edward Thomson
73d121f1ff 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 21:36:52 +01:00
Kevin Saul
68bac3f8b9 config: fix crash after memory backend entry freed 2026-04-29 21:36:52 +01:00
Kevin Saul
19e5738d80 config: update memory backend test to reproduce crash 2026-04-29 21:36:52 +01:00
Oliver Chang
4c2fdc7ed2 Fixed a heap-buffer-overflow in the smart_pkt.c:set_data function.
The strstr call used to find the " object-format=" capability string did
not have a length limit, potentially reading past the end of the
allocated buffer if the capabilities string was not null-terminated
within the buffer bounds. Replaced strstr with git__memmem and
subsequent strchr calls with memchr, providing the remaining buffer
length as a limit to prevent out-of-bounds reads.

https: //oss-fuzz.com/testcase-detail/4895812384325632
https: //issues.oss-fuzz.com/issues/42524461
Change-Id: Id313af1bce48ea8763fa2dfd7eb9ee8934fa541f
2026-04-29 21:36:52 +01:00
Weihang Lo
28ccde8d72 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-29 14:22:12 +01:00
Weihang Lo
db20a0511b 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-29 14:22:12 +01:00
Weihang Lo
390654b83e 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-29 14:22:12 +01:00
Weihang Lo
95cbdc0386 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-29 14:22:12 +01:00
Daniel Scherzer
dbe042bf85 GIT_REMOTE_DOWNLOAD_TAGS_ALL: remove stray "the" in docs 2026-04-29 14:22:12 +01:00
Edward Thomson
32d912f369 Apply suggestions from code review
Co-authored-by: Edward Thomson <ethomson@edwardthomson.com>
2026-04-29 14:22:12 +01:00
Weihang Lo
ebb93a0ef2 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-29 14:22:11 +01:00
Weihang Lo
3f20e0c71b 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-29 14:22:11 +01:00
Sven Strickroth
d5f5af2490 repo: Fix possible null pointer dereference
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2026-04-29 14:22:11 +01:00
Kovacsics Robert
f223ba4257 revparse: Allow HEAD abbreviation @
The `@` alone (without predeeding refname in `<refname>@`) is an
alias for HEAD, and can then be used with other modifiers for example
`HEAD^{/...}`
2026-04-29 14:22:11 +01:00
Chris Hoffman
47e42db06b futils: fix undefined behavior in O_FSYNC fallback definition
The fallback definition of O_FSYNC uses `(1 << 31)`, which is undefined
behavior in C. The literal `1` is a signed int, and left-shifting into
the sign bit of a signed integer is undefined per the C standard.

This causes crashes on arm64 Linux with musl libc (which doesn't define
O_FSYNC), manifesting as:

    thread panic: left shift of 1 by 31 places cannot be represented
    in type 'int'

Fall back to O_SYNC when available, since it is the POSIX standard name
for the same flag. On platforms where neither is defined (e.g. Windows),
use (1 << 30) as a sentinel value that avoids the sign bit.
2026-04-29 14:22:11 +01:00
Carlos Martín Nieto
e2621b7528 camke: include libssh2 in Requires.private in the PC file
We need this in order for `pkg-config` to be able to tell what you should link
against when building libgit2 statically. We do include libssh2 in
`Libs.private` but not in `Requires.private`. The difference is a bit subtle but
has become important.

You can call `pkg-config --libs --static ${build}/libgit2.pc` and it will give
you what is in the Libs line, and also what the packages from the Requires field
have in theirs. This is what e.g. `rugged` does and it has been working until
recently. An update to openssl to require zstd now means that using `--libs
--static` returns `-lzstd` as well as many others. This means that those who
want to link using that command now need to have the development packages for
zstd installed, which should not be necessary as libgit2 itself doesn't want to
use anything from it.

A better command to use here seems to be `pkg-config --libs --static --pure
${build}/libgit2.pc`. The manpage and help output are not very precise but what
this does is limit the list of dependencies to a single layer, which is what we
want as we would only want to link statically against libgit2 and not the rest
of the libraries.

But trying to do so breaks building with libssh2 as it's included in the Libs
field rather than the Requires, so that command excludes any linking to libssh2.

Put libssh2 in the `Requires.private` field so we correctly express we need to
link to it when linking statically.

This is unfortunately an imperfect fix as now, if we did not find libssh2 via
pkg-config but rather via CMake's `find_package`, the combination of `--static
--pure` does not take `Libs.private` into account. However we only support this
as an edge case and we expect `pkg-config` to be available for the rest of our
dependencies.
2026-04-29 14:22:11 +01:00
Edward Thomson
e307ea42c2 pcre: actually fix dangling-pointer warning 2026-04-29 14:22:11 +01:00
Edward Thomson
93042e319c pcre: update cmake warnings for non-gcc 2026-04-29 14:22:11 +01:00
Edward Thomson
66aad27219 hashmap: tests initialize to NULL to avoid warnings 2026-04-29 14:22:11 +01:00
Edward Thomson
ee7f46abc7 config: tests set entry to NULL to avoid warnings 2026-04-29 14:22:11 +01:00
Edward Thomson
207827b0e7 pcre: avoid false positive dangling pointer warning
PCRE sets the contents of an external structure to a local pointer
temporarily. gcc warns about this. Silence that dangling pointer
warning.
2026-04-29 14:22:11 +01:00
bakersdozen123
bafae68b98 Fix git_index_entry documentation
Change from "Documentation/technical/index-format.txt" to "Documentation/gitformat-index.adoc". Fixes #7115.
2026-04-29 14:22:11 +01:00
Edward Thomson
5652c13f9f config: consistent error messages 2026-04-29 14:22:11 +01:00
Weihang Lo
b0da7638ee fix(smart): keep caps across RPC stream resets
Preserve ref-advertised capabilities when only the stream is reset.

This prevents losing `object-format` before `git_remote_oid_type()`
and fixes SHA256 clone pack trailer mismatch.

Fixes libgit2/libgit2#7182
2026-04-29 14:22:11 +01:00
Weihang Lo
bc171eb33e feat(remote): expose git_remote_oid_type
This would be useful for user to determine whether they want to proceed
or bail further remote operations. Particularily useful for downstream
libgit2 bindings and applications to experiment SHA256 support behind a
runtime feature flag.

For example, `cargo` could compile with sha256 support unconditionally,
but reject SHA256 usage at runtime if the `-Zgit=sha256` nightly flag
was not on. Cargo would leverage this new API to determine if users are
trying to fetch a SHA256 remote repository and bail when needed before
any fetches happen.

Note that this is not gated behind `GIT_EXPERIMENTAL_SHA256` as the
oid_type is sha1 and available always.
2026-04-29 14:22:11 +01:00
Orgad Shaneh
174969af9b config: Fix potential null value passed to %s
config.c:1448:59: warning: '%s' directive argument is null [-Wformat-overflow=]
 1448 |         git_error_set(GIT_ERROR_CONFIG, "failed to parse '%s' as a boolean value", value);
      |                                                           ^~
2026-04-29 14:22:11 +01:00
Johannes Wilde
4e29f74404 Avoid duplicate definition of git_http_auth_dummy.
src\libgit2\transports\auth_negotiate.h redefines git_http_auth_negotiate as git_http_auth_dummy if GIT_AUTH_NEGOTIATE is not defined, which thus leads to the uncommented code actually being a redifintion of git_http_auth_dummy. The linker complained [Windows 11, MSVC 2022 64bit].
2026-04-29 13:50:35 +01:00
Edward Thomson
c49a4cbed4 index: support USE_NSEC=OFF
Ideally, nobody should be building without nanosecond precision. But
support them if they do.
2026-04-29 13:12:18 +01:00
Alf Henrik Sauge
3d973c4c17 Use git_oid_raw_cmp instead of custom loop in git_oid_is_zero
Since git_oid_raw_cmp uses memcmp, it's far easier to optimise more aggressively.
Given that it's static const and used inlined, it seems reasonable to assume that git_oid_zero will be optimised away in release. 
This is at least the case with x86-64 and GCC 15.2.1.
2026-04-29 10:22:24 +01:00
Martin Marmsoler
7c24756417 fix wrong comment 2026-04-29 10:22:19 +01:00
Weihang Lo
2bae1b5470 fix(sha256): pass correct oid type
These are SHA256 TODO leftover.
In the surrounding context they all have the required oid type around,
so I just picked up them and pass in.

Found during SHA256 support integration with Rust git-rs binding
2026-04-29 10:22:12 +01:00
qaqland
2c34cc73d2 examples: correct git_commit_time comment 2026-04-29 10:22:02 +01:00
Oblivionsage
60a9ffba60 delta: fix undefined behavior in hdr_sz varint parsing
The expression (c & 0x7f) << shift in hdr_sz() causes undefined
behavior when shift >= 32, because (c & 0x7f) is an unsigned int
(32-bit type). A malicious delta with a long varint can trigger this.

Fix by:
1. Casting to size_t before shifting to support 64-bit shifts
2. Adding a shift limit check to reject overlong varints
2026-04-29 10:21:54 +01:00
Łukasz Langa
399292dd5f Some versions of leaks want -exclude to not have a space 2026-04-29 10:21:09 +01:00