Merge branch 'js/pack-objects-delta-size-t'
The 'pack-objects' and delta-encoding code paths have been updated to use 'size_t' instead of 'unsigned long' for object sizes and offset limits, avoiding potential truncation issues on 64-bit Windows. * js/pack-objects-delta-size-t: packfile: widen `unpack_object_header_buffer()` to `size_t` git-zlib: widen `git_deflate_bound()` to `size_t` t/helper/test-pack-deltas: widen `do_compress()`'s maxsize local to `size_t` http-push: widen `start_put()`'s size local from `ssize_t` to `size_t` diff: widen `deflate_it()`'s bound local from int to `size_t` archive-zip: widen `zlib_deflate_raw()`'s maxsize local to `size_t` packfile, git-zlib: widen `use_pack()` and zstream avail fields to `size_t` delta: widen `create_delta()` and `diff_delta()` to `size_t` pack-objects: widen `mem_usage` and `try_delta()`'s out-param to `size_t` pack-objects: widen `free_unpacked()` return to `size_t` pack-objects: widen delta-cache accounting to `size_t` delta: widen `create_delta_index()` parameter to `size_t` diff-delta: widen `struct delta_index`' size fields to `size_t`main
commit
781fd4ea83
|
|
@ -206,7 +206,7 @@ static void *zlib_deflate_raw(void *data, unsigned long size,
|
||||||
unsigned long *compressed_size)
|
unsigned long *compressed_size)
|
||||||
{
|
{
|
||||||
git_zstream stream;
|
git_zstream stream;
|
||||||
unsigned long maxsize;
|
size_t maxsize;
|
||||||
void *buffer;
|
void *buffer;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -980,7 +980,7 @@ static int store_object(
|
||||||
struct object_entry *e;
|
struct object_entry *e;
|
||||||
unsigned char hdr[96];
|
unsigned char hdr[96];
|
||||||
struct object_id oid;
|
struct object_id oid;
|
||||||
unsigned long hdrlen, deltalen;
|
unsigned long hdrlen, deltalen = 0;
|
||||||
struct git_hash_ctx c;
|
struct git_hash_ctx c;
|
||||||
git_zstream s;
|
git_zstream s;
|
||||||
struct repo_config_values *cfg = repo_config_values(the_repository);
|
struct repo_config_values *cfg = repo_config_values(the_repository);
|
||||||
|
|
@ -1016,11 +1016,13 @@ static int store_object(
|
||||||
|
|
||||||
if (last && last->data.len && last->data.buf && last->depth < max_depth
|
if (last && last->data.len && last->data.buf && last->depth < max_depth
|
||||||
&& dat->len > the_hash_algo->rawsz) {
|
&& dat->len > the_hash_algo->rawsz) {
|
||||||
|
size_t deltalen_st;
|
||||||
|
|
||||||
delta_count_attempts_by_type[type]++;
|
delta_count_attempts_by_type[type]++;
|
||||||
delta = diff_delta(last->data.buf, last->data.len,
|
delta = diff_delta(last->data.buf, last->data.len,
|
||||||
dat->buf, dat->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
|
} else
|
||||||
delta = NULL;
|
delta = NULL;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -261,8 +261,8 @@ static int exclude_promisor_objects_best_effort;
|
||||||
|
|
||||||
static int use_delta_islands;
|
static int use_delta_islands;
|
||||||
|
|
||||||
static unsigned long delta_cache_size = 0;
|
static size_t delta_cache_size = 0;
|
||||||
static unsigned long max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE;
|
static size_t max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE;
|
||||||
static unsigned long cache_max_small_delta_size = 1000;
|
static unsigned long cache_max_small_delta_size = 1000;
|
||||||
|
|
||||||
static unsigned long window_memory_limit = 0;
|
static unsigned long window_memory_limit = 0;
|
||||||
|
|
@ -354,7 +354,8 @@ static void index_commit_for_bitmap(struct commit *commit)
|
||||||
|
|
||||||
static void *get_delta(struct object_entry *entry)
|
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;
|
void *buf, *base_buf, *delta_buf;
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
size_t size_st = 0, base_size_st = 0;
|
size_t size_st = 0, base_size_st = 0;
|
||||||
|
|
@ -488,7 +489,7 @@ static void copy_pack_data(struct hashfile *f,
|
||||||
off_t len)
|
off_t len)
|
||||||
{
|
{
|
||||||
unsigned char *in;
|
unsigned char *in;
|
||||||
unsigned long avail;
|
size_t avail;
|
||||||
|
|
||||||
while (len) {
|
while (len) {
|
||||||
in = use_pack(p, w_curs, offset, &avail);
|
in = use_pack(p, w_curs, offset, &avail);
|
||||||
|
|
@ -2259,8 +2260,7 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
|
||||||
int have_base = 0;
|
int have_base = 0;
|
||||||
struct object_id base_ref;
|
struct object_id base_ref;
|
||||||
struct object_entry *base_entry;
|
struct object_entry *base_entry;
|
||||||
unsigned long used, used_0;
|
size_t used, used_0, avail;
|
||||||
unsigned long avail;
|
|
||||||
off_t ofs;
|
off_t ofs;
|
||||||
unsigned char *buf, c;
|
unsigned char *buf, c;
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
|
|
@ -2688,8 +2688,8 @@ struct unpacked {
|
||||||
unsigned depth;
|
unsigned depth;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int delta_cacheable(unsigned long src_size, unsigned long trg_size,
|
static int delta_cacheable(size_t src_size, size_t trg_size,
|
||||||
unsigned long delta_size)
|
size_t delta_size)
|
||||||
{
|
{
|
||||||
if (max_delta_cache_size && delta_cache_size + delta_size > max_delta_cache_size)
|
if (max_delta_cache_size && delta_cache_size + delta_size > max_delta_cache_size)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -2772,8 +2772,7 @@ size_t oe_get_size_slow(struct packing_data *pack,
|
||||||
struct pack_window *w_curs;
|
struct pack_window *w_curs;
|
||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
unsigned long used, avail;
|
size_t used, avail, size;
|
||||||
size_t size;
|
|
||||||
|
|
||||||
if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) {
|
if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) {
|
||||||
size_t sz;
|
size_t sz;
|
||||||
|
|
@ -2804,11 +2803,12 @@ size_t oe_get_size_slow(struct packing_data *pack,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int try_delta(struct unpacked *trg, struct unpacked *src,
|
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 *trg_entry = trg->entry;
|
||||||
struct object_entry *src_entry = src->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;
|
unsigned ref_depth;
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
void *delta_buf;
|
void *delta_buf;
|
||||||
|
|
@ -2972,9 +2972,9 @@ static unsigned int check_delta_limit(struct object_entry *me, unsigned int n)
|
||||||
return m;
|
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);
|
free_delta_index(n->index);
|
||||||
n->index = NULL;
|
n->index = NULL;
|
||||||
if (n->data) {
|
if (n->data) {
|
||||||
|
|
@ -2991,7 +2991,7 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
|
||||||
{
|
{
|
||||||
uint32_t i, idx = 0, count = 0;
|
uint32_t i, idx = 0, count = 0;
|
||||||
struct unpacked *array;
|
struct unpacked *array;
|
||||||
unsigned long mem_usage = 0;
|
size_t mem_usage = 0;
|
||||||
|
|
||||||
CALLOC_ARRAY(array, window);
|
CALLOC_ARRAY(array, window);
|
||||||
|
|
||||||
|
|
@ -3701,7 +3701,7 @@ static int git_pack_config(const char *k, const char *v,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!strcmp(k, "pack.deltacachesize")) {
|
if (!strcmp(k, "pack.deltacachesize")) {
|
||||||
max_delta_cache_size = git_config_int(k, v, ctx->kvi);
|
max_delta_cache_size = git_config_size_t(k, v, ctx->kvi);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!strcmp(k, "pack.deltacachelimit")) {
|
if (!strcmp(k, "pack.deltacachelimit")) {
|
||||||
|
|
|
||||||
9
config.c
9
config.c
|
|
@ -1271,6 +1271,15 @@ ssize_t git_config_ssize_t(const char *name, const char *value,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t git_config_size_t(const char *name, const char *value,
|
||||||
|
const struct key_value_info *kvi)
|
||||||
|
{
|
||||||
|
size_t ret;
|
||||||
|
if (!git_parse_size_t(value, &ret))
|
||||||
|
die_bad_number(name, value, kvi);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
double git_config_double(const char *name, const char *value,
|
double git_config_double(const char *name, const char *value,
|
||||||
const struct key_value_info *kvi)
|
const struct key_value_info *kvi)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
3
config.h
3
config.h
|
|
@ -282,6 +282,9 @@ unsigned long git_config_ulong(const char *, const char *,
|
||||||
ssize_t git_config_ssize_t(const char *, const char *,
|
ssize_t git_config_ssize_t(const char *, const char *,
|
||||||
const struct key_value_info *);
|
const struct key_value_info *);
|
||||||
|
|
||||||
|
size_t git_config_size_t(const char *, const char *,
|
||||||
|
const struct key_value_info *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identically to `git_config_double`, but for double-precision floating point
|
* Identically to `git_config_double`, but for double-precision floating point
|
||||||
* values.
|
* values.
|
||||||
|
|
|
||||||
14
delta.h
14
delta.h
|
|
@ -14,7 +14,7 @@ struct delta_index;
|
||||||
* using free_delta_index().
|
* using free_delta_index().
|
||||||
*/
|
*/
|
||||||
struct 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()
|
* free_delta_index: free the index created by create_delta_index()
|
||||||
|
|
@ -28,7 +28,7 @@ void free_delta_index(struct delta_index *index);
|
||||||
*
|
*
|
||||||
* Given pointer must be what create_delta_index() returned, or NULL.
|
* Given pointer must be what create_delta_index() returned, or NULL.
|
||||||
*/
|
*/
|
||||||
unsigned long sizeof_delta_index(struct delta_index *index);
|
size_t sizeof_delta_index(struct delta_index *index);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* create_delta: create a delta from given index for the given buffer
|
* create_delta: create a delta from given index for the given buffer
|
||||||
|
|
@ -42,8 +42,8 @@ unsigned long sizeof_delta_index(struct delta_index *index);
|
||||||
*/
|
*/
|
||||||
void *
|
void *
|
||||||
create_delta(const struct delta_index *index,
|
create_delta(const struct delta_index *index,
|
||||||
const void *buf, unsigned long bufsize,
|
const void *buf, size_t bufsize,
|
||||||
unsigned long *delta_size, unsigned long max_delta_size);
|
size_t *delta_size, size_t max_delta_size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* diff_delta: create a delta from source buffer to target buffer
|
* 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.
|
* updated with its size. The returned buffer must be freed by the caller.
|
||||||
*/
|
*/
|
||||||
static inline void *
|
static inline void *
|
||||||
diff_delta(const void *src_buf, unsigned long src_bufsize,
|
diff_delta(const void *src_buf, size_t src_bufsize,
|
||||||
const void *trg_buf, unsigned long trg_bufsize,
|
const void *trg_buf, size_t trg_bufsize,
|
||||||
unsigned long *delta_size, unsigned long max_delta_size)
|
size_t *delta_size, size_t max_delta_size)
|
||||||
{
|
{
|
||||||
struct delta_index *index = create_delta_index(src_buf, src_bufsize);
|
struct delta_index *index = create_delta_index(src_buf, src_bufsize);
|
||||||
if (index) {
|
if (index) {
|
||||||
|
|
|
||||||
14
diff-delta.c
14
diff-delta.c
|
|
@ -125,14 +125,14 @@ struct unpacked_index_entry {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct delta_index {
|
struct delta_index {
|
||||||
unsigned long memsize;
|
size_t memsize;
|
||||||
const void *src_buf;
|
const void *src_buf;
|
||||||
unsigned long src_size;
|
size_t src_size;
|
||||||
unsigned int hash_mask;
|
unsigned int hash_mask;
|
||||||
struct index_entry *hash[FLEX_ARRAY];
|
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;
|
unsigned int i, hsize, hmask, entries, prev_val, *hash_count;
|
||||||
const unsigned char *data, *buffer = buf;
|
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 unpacked_index_entry *entry, **hash;
|
||||||
struct index_entry *packed_entry, **packed_hash;
|
struct index_entry *packed_entry, **packed_hash;
|
||||||
void *mem;
|
void *mem;
|
||||||
unsigned long memsize;
|
size_t memsize;
|
||||||
|
|
||||||
if (!buf || !bufsize)
|
if (!buf || !bufsize)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -302,7 +302,7 @@ void free_delta_index(struct delta_index *index)
|
||||||
free(index);
|
free(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long sizeof_delta_index(struct delta_index *index)
|
size_t sizeof_delta_index(struct delta_index *index)
|
||||||
{
|
{
|
||||||
if (index)
|
if (index)
|
||||||
return index->memsize;
|
return index->memsize;
|
||||||
|
|
@ -318,8 +318,8 @@ unsigned long sizeof_delta_index(struct delta_index *index)
|
||||||
|
|
||||||
void *
|
void *
|
||||||
create_delta(const struct delta_index *index,
|
create_delta(const struct delta_index *index,
|
||||||
const void *trg_buf, unsigned long trg_size,
|
const void *trg_buf, size_t trg_size,
|
||||||
unsigned long *delta_size, unsigned long max_size)
|
size_t *delta_size, size_t max_size)
|
||||||
{
|
{
|
||||||
unsigned int i, val;
|
unsigned int i, val;
|
||||||
off_t outpos, moff;
|
off_t outpos, moff;
|
||||||
|
|
|
||||||
6
diff.c
6
diff.c
|
|
@ -3586,7 +3586,7 @@ static unsigned char *deflate_it(char *data,
|
||||||
unsigned long size,
|
unsigned long size,
|
||||||
unsigned long *result_size)
|
unsigned long *result_size)
|
||||||
{
|
{
|
||||||
int bound;
|
size_t bound;
|
||||||
unsigned char *deflated;
|
unsigned char *deflated;
|
||||||
git_zstream stream;
|
git_zstream stream;
|
||||||
struct repo_config_values *cfg = repo_config_values(the_repository);
|
struct repo_config_values *cfg = repo_config_values(the_repository);
|
||||||
|
|
@ -3624,9 +3624,11 @@ static void emit_binary_diff_body(struct diff_options *o,
|
||||||
delta = NULL;
|
delta = NULL;
|
||||||
deflated = deflate_it(two->ptr, two->size, &deflate_size);
|
deflated = deflate_it(two->ptr, two->size, &deflate_size);
|
||||||
if (one->size && two->size) {
|
if (one->size && two->size) {
|
||||||
|
size_t delta_size_st = 0;
|
||||||
delta = diff_delta(one->ptr, one->size,
|
delta = diff_delta(one->ptr, one->size,
|
||||||
two->ptr, two->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) {
|
if (delta) {
|
||||||
void *to_free = delta;
|
void *to_free = delta;
|
||||||
orig_size = delta_size;
|
orig_size = delta_size;
|
||||||
|
|
|
||||||
18
git-zlib.c
18
git-zlib.c
|
|
@ -33,7 +33,7 @@ static const char *zerr_to_string(int status)
|
||||||
|
|
||||||
/* uLong is 32-bit on Windows, even on 64-bit systems */
|
/* uLong is 32-bit on Windows, even on 64-bit systems */
|
||||||
#define ULONG_MAX_VALUE maximum_unsigned_value_of_type(uLong)
|
#define ULONG_MAX_VALUE maximum_unsigned_value_of_type(uLong)
|
||||||
static inline uInt zlib_buf_cap(unsigned long len)
|
static inline uInt zlib_buf_cap(size_t len)
|
||||||
{
|
{
|
||||||
return (ZLIB_BUF_MAX < len) ? ZLIB_BUF_MAX : len;
|
return (ZLIB_BUF_MAX < len) ? ZLIB_BUF_MAX : len;
|
||||||
}
|
}
|
||||||
|
|
@ -167,9 +167,21 @@ int git_inflate(git_zstream *strm, int flush)
|
||||||
return status;
|
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)
|
void git_deflate_init(git_zstream *strm, int level)
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
|
|
||||||
typedef struct git_zstream {
|
typedef struct git_zstream {
|
||||||
struct z_stream_s z;
|
struct z_stream_s z;
|
||||||
unsigned long avail_in;
|
size_t avail_in;
|
||||||
unsigned long avail_out;
|
size_t avail_out;
|
||||||
size_t total_in;
|
size_t total_in;
|
||||||
size_t total_out;
|
size_t total_out;
|
||||||
unsigned char *next_in;
|
unsigned char *next_in;
|
||||||
|
|
@ -25,6 +25,6 @@ void git_deflate_end(git_zstream *);
|
||||||
int git_deflate_abort(git_zstream *);
|
int git_deflate_abort(git_zstream *);
|
||||||
int git_deflate_end_gently(git_zstream *);
|
int git_deflate_end_gently(git_zstream *);
|
||||||
int git_deflate(git_zstream *, int flush);
|
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 */
|
#endif /* GIT_ZLIB_H */
|
||||||
|
|
|
||||||
|
|
@ -367,7 +367,7 @@ static void start_put(struct transfer_request *request)
|
||||||
void *unpacked;
|
void *unpacked;
|
||||||
size_t len;
|
size_t len;
|
||||||
int hdrlen;
|
int hdrlen;
|
||||||
ssize_t size;
|
size_t size;
|
||||||
git_zstream stream;
|
git_zstream stream;
|
||||||
struct repo_config_values *cfg = repo_config_values(the_repository);
|
struct repo_config_values *cfg = repo_config_values(the_repository);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
unpack_object_header_buffer((const unsigned char *)data,
|
unpack_object_header_buffer((const unsigned char *)data,
|
||||||
(unsigned long)size, &type, &len);
|
size, &type, &len);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
uint32_t data_crc = crc32(0, NULL, 0);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
unsigned long avail;
|
size_t avail;
|
||||||
void *data = use_pack(p, w_curs, offset, &avail);
|
void *data = use_pack(p, w_curs, offset, &avail);
|
||||||
if (avail > len)
|
if (avail > len)
|
||||||
avail = len;
|
avail = len;
|
||||||
|
|
@ -71,7 +71,7 @@ static int verify_packfile(struct repository *r,
|
||||||
|
|
||||||
git_hash_init(&ctx, r->hash_algo);
|
git_hash_init(&ctx, r->hash_algo);
|
||||||
do {
|
do {
|
||||||
unsigned long remaining;
|
size_t remaining;
|
||||||
unsigned char *in = use_pack(p, w_curs, offset, &remaining);
|
unsigned char *in = use_pack(p, w_curs, offset, &remaining);
|
||||||
offset += remaining;
|
offset += remaining;
|
||||||
if (!pack_sig_ofs)
|
if (!pack_sig_ofs)
|
||||||
|
|
|
||||||
12
packfile.c
12
packfile.c
|
|
@ -620,7 +620,7 @@ static int in_window(struct repository *r, struct pack_window *win,
|
||||||
unsigned char *use_pack(struct packed_git *p,
|
unsigned char *use_pack(struct packed_git *p,
|
||||||
struct pack_window **w_cursor,
|
struct pack_window **w_cursor,
|
||||||
off_t offset,
|
off_t offset,
|
||||||
unsigned long *left)
|
size_t *left)
|
||||||
{
|
{
|
||||||
struct pack_window *win = *w_cursor;
|
struct pack_window *win = *w_cursor;
|
||||||
|
|
||||||
|
|
@ -866,12 +866,11 @@ struct packfile_list_entry *packfile_store_get_packs(struct odb_source_packed *s
|
||||||
return store->packs.head;
|
return store->packs.head;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long unpack_object_header_buffer(const unsigned char *buf,
|
size_t unpack_object_header_buffer(const unsigned char *buf, size_t len,
|
||||||
unsigned long len, enum object_type *type, size_t *sizep)
|
enum object_type *type, size_t *sizep)
|
||||||
{
|
{
|
||||||
unsigned shift;
|
unsigned shift;
|
||||||
size_t size, c;
|
size_t size, c, used = 0;
|
||||||
unsigned long used = 0;
|
|
||||||
|
|
||||||
c = buf[used++];
|
c = buf[used++];
|
||||||
*type = (c >> 4) & 7;
|
*type = (c >> 4) & 7;
|
||||||
|
|
@ -960,8 +959,7 @@ int unpack_object_header(struct packed_git *p,
|
||||||
size_t *sizep)
|
size_t *sizep)
|
||||||
{
|
{
|
||||||
unsigned char *base;
|
unsigned char *base;
|
||||||
unsigned long left;
|
size_t left, used;
|
||||||
unsigned long used;
|
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
|
|
||||||
/* use_pack() assures us we have [base, base + 20) available
|
/* use_pack() assures us we have [base, base + 20) available
|
||||||
|
|
|
||||||
|
|
@ -240,7 +240,8 @@ uint32_t get_pack_fanout(struct packed_git *p, uint32_t value);
|
||||||
|
|
||||||
struct object_database;
|
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_windows(struct packed_git *);
|
||||||
void close_pack(struct packed_git *);
|
void close_pack(struct packed_git *);
|
||||||
void unuse_pack(struct pack_window **);
|
void unuse_pack(struct pack_window **);
|
||||||
|
|
@ -299,7 +300,8 @@ int packfile_fill_entry(struct packed_git *p,
|
||||||
int is_pack_valid(struct packed_git *);
|
int is_pack_valid(struct packed_git *);
|
||||||
void *unpack_entry(struct repository *r, struct packed_git *, off_t,
|
void *unpack_entry(struct repository *r, struct packed_git *, off_t,
|
||||||
enum object_type *, size_t *);
|
enum object_type *, size_t *);
|
||||||
unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, size_t *sizep);
|
size_t unpack_object_header_buffer(const unsigned char *buf, size_t len,
|
||||||
|
enum object_type *type, size_t *sizep);
|
||||||
size_t get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
|
size_t get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
|
||||||
int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, size_t *);
|
int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, size_t *);
|
||||||
off_t get_delta_base(struct packed_git *p, struct pack_window **w_curs,
|
off_t get_delta_base(struct packed_git *p, struct pack_window **w_curs,
|
||||||
|
|
|
||||||
9
parse.c
9
parse.c
|
|
@ -134,6 +134,15 @@ int git_parse_ssize_t(const char *value, ssize_t *ret)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int git_parse_size_t(const char *value, size_t *ret)
|
||||||
|
{
|
||||||
|
uintmax_t tmp;
|
||||||
|
if (!git_parse_unsigned(value, &tmp, maximum_signed_value_of_type(size_t)))
|
||||||
|
return 0;
|
||||||
|
*ret = tmp;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int git_parse_double(const char *value, double *ret)
|
int git_parse_double(const char *value, double *ret)
|
||||||
{
|
{
|
||||||
char *end;
|
char *end;
|
||||||
|
|
|
||||||
1
parse.h
1
parse.h
|
|
@ -4,6 +4,7 @@
|
||||||
int git_parse_signed(const char *value, intmax_t *ret, intmax_t max);
|
int git_parse_signed(const char *value, intmax_t *ret, intmax_t max);
|
||||||
int git_parse_unsigned(const char *value, uintmax_t *ret, uintmax_t max);
|
int git_parse_unsigned(const char *value, uintmax_t *ret, uintmax_t max);
|
||||||
int git_parse_ssize_t(const char *, ssize_t *);
|
int git_parse_ssize_t(const char *, ssize_t *);
|
||||||
|
int git_parse_size_t(const char *, size_t *);
|
||||||
int git_parse_ulong(const char *, unsigned long *);
|
int git_parse_ulong(const char *, unsigned long *);
|
||||||
int git_parse_uint(const char *value, unsigned int *ret);
|
int git_parse_uint(const char *value, unsigned int *ret);
|
||||||
int git_parse_int(const char *value, int *ret);
|
int git_parse_int(const char *value, int *ret);
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ int cmd__delta(int argc, const char **argv)
|
||||||
die_errno("unable to read '%s'", argv[3]);
|
die_errno("unable to read '%s'", argv[3]);
|
||||||
|
|
||||||
if (argv[1][1] == 'd') {
|
if (argv[1][1] == 'd') {
|
||||||
unsigned long delta_size;
|
size_t delta_size;
|
||||||
out_buf = diff_delta(from.buf, from.len,
|
out_buf = diff_delta(from.buf, from.len,
|
||||||
data.buf, data.len,
|
data.buf, data.len,
|
||||||
&delta_size, 0);
|
&delta_size, 0);
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ static unsigned long do_compress(void **pptr, unsigned long size)
|
||||||
{
|
{
|
||||||
git_zstream stream;
|
git_zstream stream;
|
||||||
void *in, *out;
|
void *in, *out;
|
||||||
unsigned long maxsize;
|
size_t maxsize;
|
||||||
|
|
||||||
git_deflate_init(&stream, 1);
|
git_deflate_init(&stream, 1);
|
||||||
maxsize = git_deflate_bound(&stream, size);
|
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 char header[MAX_PACK_OBJECT_HEADER];
|
||||||
unsigned long delta_size, compressed_size, hdrlen;
|
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;
|
enum object_type type;
|
||||||
void *base_buf, *delta_buf;
|
void *base_buf, *delta_buf;
|
||||||
void *buf = odb_read_object(the_repository->objects,
|
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));
|
die("unable to read %s", oid_to_hex(base));
|
||||||
|
|
||||||
delta_buf = diff_delta(base_buf, base_size,
|
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);
|
compressed_size = do_compress(&delta_buf, delta_size);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue