Merge branch 'size-t/pack-objects-delta'

This commit is contained in:
Johannes Schindelin
2026-06-07 23:13:54 +02:00
18 changed files with 94 additions and 47 deletions

View File

@@ -420,7 +420,9 @@ jobs:
CI_JOB_IMAGE: ${{matrix.vector.image}}
CUSTOM_PATH: /custom
runs-on: ubuntu-latest
container: ${{matrix.vector.image}}
container:
image: ${{ matrix.vector.image }}
options: ${{ github.repository_visibility == 'private' && '--pids-limit 16384 --ulimit nproc=16384:16384 --ulimit nofile=32768:32768' || '' }}
steps:
- name: prepare libc6 for actions
if: matrix.vector.jobname == 'linux32'

View File

@@ -206,7 +206,7 @@ static void *zlib_deflate_raw(void *data, unsigned long size,
unsigned long *compressed_size)
{
git_zstream stream;
unsigned long maxsize;
size_t maxsize;
void *buffer;
int result;

View File

@@ -998,11 +998,13 @@ static int store_object(
if (last && last->data.len && last->data.buf && last->depth < max_depth
&& dat->len > the_hash_algo->rawsz) {
size_t deltalen_st = 0;
delta_count_attempts_by_type[type]++;
delta = diff_delta(last->data.buf, last->data.len,
dat->buf, dat->len,
&deltalen, dat->len - the_hash_algo->rawsz);
&deltalen_st, dat->len - the_hash_algo->rawsz);
deltalen = cast_size_t_to_ulong(deltalen_st);
} else
delta = NULL;

View File

@@ -260,8 +260,8 @@ static int exclude_promisor_objects_best_effort;
static int use_delta_islands;
static unsigned long delta_cache_size = 0;
static unsigned long max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE;
static size_t delta_cache_size = 0;
static size_t max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE;
static unsigned long cache_max_small_delta_size = 1000;
static unsigned long window_memory_limit = 0;
@@ -353,7 +353,8 @@ static void index_commit_for_bitmap(struct commit *commit)
static void *get_delta(struct object_entry *entry)
{
unsigned long size, base_size, delta_size;
unsigned long size, base_size;
size_t delta_size;
void *buf, *base_buf, *delta_buf;
enum object_type type;
size_t size_st = 0, base_size_st = 0;
@@ -487,7 +488,7 @@ static void copy_pack_data(struct hashfile *f,
off_t len)
{
unsigned char *in;
unsigned long avail;
size_t avail;
while (len) {
in = use_pack(p, w_curs, offset, &avail);
@@ -2259,7 +2260,7 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
struct object_id base_ref;
struct object_entry *base_entry;
unsigned long used, used_0;
unsigned long avail;
size_t avail;
off_t ofs;
unsigned char *buf, c;
enum object_type type;
@@ -2687,8 +2688,8 @@ struct unpacked {
unsigned depth;
};
static int delta_cacheable(unsigned long src_size, unsigned long trg_size,
unsigned long delta_size)
static int delta_cacheable(size_t src_size, size_t trg_size,
size_t delta_size)
{
if (max_delta_cache_size && delta_cache_size + delta_size > max_delta_cache_size)
return 0;
@@ -2755,8 +2756,8 @@ size_t oe_get_size_slow(struct packing_data *pack,
struct pack_window *w_curs;
unsigned char *buf;
enum object_type type;
unsigned long used, avail;
size_t size;
unsigned long used;
size_t avail, size;
if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) {
size_t sz;
@@ -2787,11 +2788,12 @@ size_t oe_get_size_slow(struct packing_data *pack,
}
static int try_delta(struct unpacked *trg, struct unpacked *src,
unsigned max_depth, unsigned long *mem_usage)
unsigned max_depth, size_t *mem_usage)
{
struct object_entry *trg_entry = trg->entry;
struct object_entry *src_entry = src->entry;
unsigned long trg_size, src_size, delta_size, sizediff, max_size, sz;
unsigned long trg_size, src_size, sizediff, max_size, sz;
size_t delta_size;
unsigned ref_depth;
enum object_type type;
void *delta_buf;
@@ -2955,9 +2957,9 @@ static unsigned int check_delta_limit(struct object_entry *me, unsigned int n)
return m;
}
static unsigned long free_unpacked(struct unpacked *n)
static size_t free_unpacked(struct unpacked *n)
{
unsigned long freed_mem = sizeof_delta_index(n->index);
size_t freed_mem = sizeof_delta_index(n->index);
free_delta_index(n->index);
n->index = NULL;
if (n->data) {
@@ -2974,7 +2976,7 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
{
uint32_t i, idx = 0, count = 0;
struct unpacked *array;
unsigned long mem_usage = 0;
size_t mem_usage = 0;
CALLOC_ARRAY(array, window);

View File

@@ -352,6 +352,29 @@ process_phantom_symlink(const wchar_t *wtarget, const wchar_t *wlink)
wchar_t relative[MAX_PATH];
const wchar_t *rel;
/*
* Do not follow symlinks to network shares, to avoid NTLM credential
* leak from crafted repositories (e.g. \\attacker-server\share).
* Since paths come in all kind of enterprising shapes and forms (in
* addition to the canonical `\\host\share` form, there's also
* `\??\UNC\host\share`, `\GLOBAL??\UNC\host\share` and also
* `\Device\Mup\host\share`, just to name a few), we simply avoid
* following every symlink target that starts with a slash.
*
* This also catches drive-less absolute paths, of course. These are
* uncommon in practice (and also fragile because they are relative to
* the current working directory's drive). The only "harm" this does
* is that it now requires users to specify via the Git attributes if
* they have such an uncommon symbolic link and need it to be a
* directory type link.
*/
if (is_wdir_sep(wtarget[0])) {
warning("created file symlink '%ls' pointing to '%ls';\n"
"set the `symlink` gitattribute to `dir` if a "
"directory symlink is required", wlink, wtarget);
return PHANTOM_SYMLINK_DONE;
}
/* check that wlink is still a file symlink */
if ((GetFileAttributesW(wlink)
& (FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_DIRECTORY))

12
delta.h
View File

@@ -14,7 +14,7 @@ struct delta_index;
* using free_delta_index().
*/
struct delta_index *
create_delta_index(const void *buf, unsigned long bufsize);
create_delta_index(const void *buf, size_t bufsize);
/*
* free_delta_index: free the index created by create_delta_index()
@@ -42,8 +42,8 @@ unsigned long sizeof_delta_index(struct delta_index *index);
*/
void *
create_delta(const struct delta_index *index,
const void *buf, unsigned long bufsize,
unsigned long *delta_size, unsigned long max_delta_size);
const void *buf, size_t bufsize,
size_t *delta_size, size_t max_delta_size);
/*
* diff_delta: create a delta from source buffer to target buffer
@@ -54,9 +54,9 @@ create_delta(const struct delta_index *index,
* updated with its size. The returned buffer must be freed by the caller.
*/
static inline void *
diff_delta(const void *src_buf, unsigned long src_bufsize,
const void *trg_buf, unsigned long trg_bufsize,
unsigned long *delta_size, unsigned long max_delta_size)
diff_delta(const void *src_buf, size_t src_bufsize,
const void *trg_buf, size_t trg_bufsize,
size_t *delta_size, size_t max_delta_size)
{
struct delta_index *index = create_delta_index(src_buf, src_bufsize);
if (index) {

View File

@@ -125,14 +125,14 @@ struct unpacked_index_entry {
};
struct delta_index {
unsigned long memsize;
size_t memsize;
const void *src_buf;
unsigned long src_size;
size_t src_size;
unsigned int hash_mask;
struct index_entry *hash[FLEX_ARRAY];
};
struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
struct delta_index * create_delta_index(const void *buf, size_t bufsize)
{
unsigned int i, hsize, hmask, entries, prev_val, *hash_count;
const unsigned char *data, *buffer = buf;
@@ -140,7 +140,7 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
struct unpacked_index_entry *entry, **hash;
struct index_entry *packed_entry, **packed_hash;
void *mem;
unsigned long memsize;
size_t memsize;
if (!buf || !bufsize)
return NULL;
@@ -318,8 +318,8 @@ unsigned long sizeof_delta_index(struct delta_index *index)
void *
create_delta(const struct delta_index *index,
const void *trg_buf, unsigned long trg_size,
unsigned long *delta_size, unsigned long max_size)
const void *trg_buf, size_t trg_size,
size_t *delta_size, size_t max_size)
{
unsigned int i, val;
off_t outpos, moff;

6
diff.c
View File

@@ -3609,7 +3609,7 @@ static unsigned char *deflate_it(char *data,
unsigned long size,
unsigned long *result_size)
{
int bound;
size_t bound;
unsigned char *deflated;
git_zstream stream;
struct repo_config_values *cfg = repo_config_values(the_repository);
@@ -3647,9 +3647,11 @@ static void emit_binary_diff_body(struct diff_options *o,
delta = NULL;
deflated = deflate_it(two->ptr, two->size, &deflate_size);
if (one->size && two->size) {
size_t delta_size_st = 0;
delta = diff_delta(one->ptr, one->size,
two->ptr, two->size,
&delta_size, deflate_size);
&delta_size_st, deflate_size);
delta_size = cast_size_t_to_ulong(delta_size_st);
if (delta) {
void *to_free = delta;
orig_size = delta_size;

View File

@@ -167,9 +167,21 @@ int git_inflate(git_zstream *strm, int flush)
return status;
}
unsigned long git_deflate_bound(git_zstream *strm, unsigned long size)
size_t git_deflate_bound(git_zstream *strm, size_t size)
{
return deflateBound(&strm->z, size);
#if SIZE_MAX > ULONG_MAX
if (size > maximum_unsigned_value_of_type(uLong))
/*
* deflateBound() takes uLong, which is 32-bit on
* Windows. For inputs above that range, return zlib's
* stored-block formula (the conservative path it would
* itself use for an unknown stream state) plus the
* worst-case wrapper overhead.
*/
return size + (size >> 5) + (size >> 7) + (size >> 11)
+ 7 + 18;
#endif
return deflateBound(&strm->z, (uLong)size);
}
void git_deflate_init(git_zstream *strm, int level)

View File

@@ -5,8 +5,8 @@
typedef struct git_zstream {
struct z_stream_s z;
unsigned long avail_in;
unsigned long avail_out;
size_t avail_in;
size_t avail_out;
size_t total_in;
size_t total_out;
unsigned char *next_in;
@@ -25,6 +25,6 @@ void git_deflate_end(git_zstream *);
int git_deflate_abort(git_zstream *);
int git_deflate_end_gently(git_zstream *);
int git_deflate(git_zstream *, int flush);
unsigned long git_deflate_bound(git_zstream *, unsigned long);
size_t git_deflate_bound(git_zstream *, size_t);
#endif /* GIT_ZLIB_H */

2
grep.c
View File

@@ -1647,6 +1647,8 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
bol = gs->buf;
left = gs->size;
if (left && gs->buf[left-1] == '\n')
left--;
while (left) {
const char *eol;
int hit;

View File

@@ -367,7 +367,7 @@ static void start_put(struct transfer_request *request)
void *unpacked;
size_t len;
int hdrlen;
ssize_t size;
size_t size;
git_zstream stream;
struct repo_config_values *cfg = repo_config_values(the_repository);

View File

@@ -34,7 +34,7 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs,
uint32_t data_crc = crc32(0, NULL, 0);
do {
unsigned long avail;
size_t avail;
void *data = use_pack(p, w_curs, offset, &avail);
if (avail > len)
avail = len;
@@ -71,7 +71,7 @@ static int verify_packfile(struct repository *r,
r->hash_algo->init_fn(&ctx);
do {
unsigned long remaining;
size_t remaining;
unsigned char *in = use_pack(p, w_curs, offset, &remaining);
offset += remaining;
if (!pack_sig_ofs)

View File

@@ -704,7 +704,7 @@ static int in_window(struct repository *r, struct pack_window *win,
unsigned char *use_pack(struct packed_git *p,
struct pack_window **w_cursor,
off_t offset,
unsigned long *left)
size_t *left)
{
struct pack_window *win = *w_cursor;
@@ -1228,7 +1228,7 @@ int unpack_object_header(struct packed_git *p,
size_t *sizep)
{
unsigned char *base;
unsigned long left;
size_t left;
unsigned long used;
enum object_type type;

View File

@@ -402,7 +402,8 @@ uint32_t get_pack_fanout(struct packed_git *p, uint32_t value);
struct object_database;
unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t,
size_t *);
void close_pack_windows(struct packed_git *);
void close_pack(struct packed_git *);
void unuse_pack(struct pack_window **);

View File

@@ -32,7 +32,7 @@ int cmd__delta(int argc, const char **argv)
die_errno("unable to read '%s'", argv[3]);
if (argv[1][1] == 'd') {
unsigned long delta_size;
size_t delta_size;
out_buf = diff_delta(from.buf, from.len,
data.buf, data.len,
&delta_size, 0);

View File

@@ -22,7 +22,7 @@ static unsigned long do_compress(void **pptr, unsigned long size)
{
git_zstream stream;
void *in, *out;
unsigned long maxsize;
size_t maxsize;
git_deflate_init(&stream, 1);
maxsize = git_deflate_bound(&stream, size);
@@ -49,7 +49,7 @@ static void write_ref_delta(struct hashfile *f,
{
unsigned char header[MAX_PACK_OBJECT_HEADER];
unsigned long delta_size, compressed_size, hdrlen;
size_t size, base_size;
size_t size, base_size, delta_size_st = 0;
enum object_type type;
void *base_buf, *delta_buf;
void *buf = odb_read_object(the_repository->objects,
@@ -65,7 +65,8 @@ static void write_ref_delta(struct hashfile *f,
die("unable to read %s", oid_to_hex(base));
delta_buf = diff_delta(base_buf, base_size,
buf, size, &delta_size, 0);
buf, size, &delta_size_st, 0);
delta_size = cast_size_t_to_ulong(delta_size_st);
compressed_size = do_compress(&delta_buf, delta_size);

View File

@@ -84,7 +84,7 @@ int unix_stream_connect(const char *path, int disallow_chdir)
struct unix_sockaddr_context ctx;
if (unix_sockaddr_init(&sa, path, &ctx, disallow_chdir) < 0)
return -1;
goto fail;
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0)
goto fail;