summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-11-28 12:42:36 +0100
committerGitHub <noreply@github.com>2019-11-28 12:42:36 +0100
commit0e5243b78ff699709d9e4ec48141a44692618f42 (patch)
tree0c2b5b3d6b31de05aadee6bb38b224236ae38a62
parent7198d3452c8c90042b4f33687052d545bf12080c (diff)
parent6460e8abcfda7692af9bd267bddf6e11a78f8130 (diff)
downloadlibgit2-0e5243b78ff699709d9e4ec48141a44692618f42.tar.gz
Merge pull request #5123 from libgit2/ethomson/off_t
Move `git_off_t` to `git_object_size_t`
-rw-r--r--examples/blame.c2
-rw-r--r--include/git2/blob.h2
-rw-r--r--include/git2/diff.h12
-rw-r--r--include/git2/object.h2
-rw-r--r--include/git2/odb.h2
-rw-r--r--include/git2/odb_backend.h4
-rw-r--r--include/git2/sys/odb_backend.h2
-rw-r--r--include/git2/types.h3
-rw-r--r--src/attr_file.c2
-rw-r--r--src/blame.c11
-rw-r--r--src/blame.h2
-rw-r--r--src/blob.c16
-rw-r--r--src/blob.h2
-rw-r--r--src/crlf.c2
-rw-r--r--src/diff_file.c8
-rw-r--r--src/diff_file.h2
-rw-r--r--src/diff_generate.c4
-rw-r--r--src/diff_generate.h4
-rw-r--r--src/diff_stats.c2
-rw-r--r--src/diff_tform.c2
-rw-r--r--src/filter.c2
-rw-r--r--src/futils.c24
-rw-r--r--src/futils.h6
-rw-r--r--src/indexer.c38
-rw-r--r--src/integer.h8
-rw-r--r--src/map.h2
-rw-r--r--src/merge.c2
-rw-r--r--src/mwindow.c18
-rw-r--r--src/mwindow.h8
-rw-r--r--src/notes.c2
-rw-r--r--src/object.h2
-rw-r--r--src/odb.c30
-rw-r--r--src/odb.h2
-rw-r--r--src/odb_loose.c4
-rw-r--r--src/offmap.c14
-rw-r--r--src/offmap.h14
-rw-r--r--src/pack-objects.h2
-rw-r--r--src/pack.c54
-rw-r--r--src/pack.h22
-rw-r--r--src/patch_parse.c4
-rw-r--r--src/posix.c2
-rw-r--r--src/posix.h12
-rw-r--r--src/reader.c2
-rw-r--r--src/repository.c7
-rw-r--r--src/unix/map.c2
-rw-r--r--src/win32/map.c8
-rw-r--r--src/win32/posix.h2
-rw-r--r--src/win32/posix_w32.c2
-rw-r--r--src/win32/w32_util.h2
-rw-r--r--tests/core/ftruncate.c2
-rw-r--r--tests/index/tests.c2
-rw-r--r--tests/object/blob/filter.c2
52 files changed, 211 insertions, 178 deletions
diff --git a/examples/blame.c b/examples/blame.c
index 76f5ed2bd..469dbd1a1 100644
--- a/examples/blame.c
+++ b/examples/blame.c
@@ -33,7 +33,7 @@ static void parse_opts(struct opts *o, int argc, char *argv[]);
int lg2_blame(git_repository *repo, int argc, char *argv[])
{
int line, break_on_null_hunk;
- git_off_t i, rawsize;
+ git_object_size_t i, rawsize;
char spec[1024] = {0};
struct opts o = {0};
const char *rawdata;
diff --git a/include/git2/blob.h b/include/git2/blob.h
index 40f922b71..7e2a745d1 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -94,7 +94,7 @@ GIT_EXTERN(const void *) git_blob_rawcontent(const git_blob *blob);
* @param blob pointer to the blob
* @return size on bytes
*/
-GIT_EXTERN(git_off_t) git_blob_rawsize(const git_blob *blob);
+GIT_EXTERN(git_object_size_t) git_blob_rawsize(const git_blob *blob);
/**
* Flags to control the functionality of `git_blob_filter`.
diff --git a/include/git2/diff.h b/include/git2/diff.h
index 73c5e55b9..490b40605 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -258,12 +258,12 @@ typedef enum {
* abbreviated to something reasonable, like 7 characters.
*/
typedef struct {
- git_oid id;
- const char *path;
- git_off_t size;
- uint32_t flags;
- uint16_t mode;
- uint16_t id_abbrev;
+ git_oid id;
+ const char *path;
+ git_object_size_t size;
+ uint32_t flags;
+ uint16_t mode;
+ uint16_t id_abbrev;
} git_diff_file;
/**
diff --git a/include/git2/object.h b/include/git2/object.h
index 2045dd8dc..984dbb7ac 100644
--- a/include/git2/object.h
+++ b/include/git2/object.h
@@ -21,6 +21,8 @@
*/
GIT_BEGIN_DECL
+#define GIT_OBJECT_SIZE_MAX UINT64_MAX
+
/**
* Lookup a reference to one of the objects in a repository.
*
diff --git a/include/git2/odb.h b/include/git2/odb.h
index e8824b727..c4bfa5290 100644
--- a/include/git2/odb.h
+++ b/include/git2/odb.h
@@ -294,7 +294,7 @@ GIT_EXTERN(int) git_odb_write(git_oid *out, git_odb *odb, const void *data, size
* @param type type of the object that will be written
* @return 0 if the stream was created; error code otherwise
*/
-GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **out, git_odb *db, git_off_t size, git_object_t type);
+GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **out, git_odb *db, git_object_size_t size, git_object_t type);
/**
* Write to an odb stream
diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h
index 47e0dd4b2..c593bac26 100644
--- a/include/git2/odb_backend.h
+++ b/include/git2/odb_backend.h
@@ -87,8 +87,8 @@ struct git_odb_stream {
unsigned int mode;
void *hash_ctx;
- git_off_t declared_size;
- git_off_t received_bytes;
+ git_object_size_t declared_size;
+ git_object_size_t received_bytes;
/**
* Write at most `len` bytes into `buffer` and advance the stream.
diff --git a/include/git2/sys/odb_backend.h b/include/git2/sys/odb_backend.h
index 6614dcf30..4dba460af 100644
--- a/include/git2/sys/odb_backend.h
+++ b/include/git2/sys/odb_backend.h
@@ -53,7 +53,7 @@ struct git_odb_backend {
git_odb_backend *, const git_oid *, const void *, size_t, git_object_t);
int GIT_CALLBACK(writestream)(
- git_odb_stream **, git_odb_backend *, git_off_t, git_object_t);
+ git_odb_stream **, git_odb_backend *, git_object_size_t, git_object_t);
int GIT_CALLBACK(readstream)(
git_odb_stream **, size_t *, git_object_t *,
diff --git a/include/git2/types.h b/include/git2/types.h
index de9ee43dd..ade0c7d32 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -63,6 +63,9 @@ typedef int64_t git_time_t; /**< time in seconds from epoch */
#endif
+/** The maximum size of an object */
+typedef uint64_t git_object_size_t;
+
#include "buffer.h"
#include "oid.h"
diff --git a/src/attr_file.c b/src/attr_file.c
index a1b4c7324..82da5268f 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -120,7 +120,7 @@ int git_attr_file__load(
int bom_offset;
git_bom_t bom;
git_oid id;
- git_off_t blobsize;
+ git_object_size_t blobsize;
*out = NULL;
diff --git a/src/blame.c b/src/blame.c
index 56b5b075a..404f1f643 100644
--- a/src/blame.c
+++ b/src/blame.c
@@ -268,7 +268,7 @@ static git_blame_hunk *split_hunk_in_vector(
static int index_blob_lines(git_blame *blame)
{
const char *buf = blame->final_buf;
- git_off_t len = blame->final_buf_size;
+ size_t len = blame->final_buf_size;
int num = 0, incomplete = 0, bol = 1;
size_t *i;
@@ -335,8 +335,15 @@ static int blame_internal(git_blame *blame)
if ((error = load_blob(blame)) < 0 ||
(error = git_blame__get_origin(&o, blame, blame->final, blame->path)) < 0)
goto cleanup;
+
+ if (git_blob_rawsize(blame->final_blob) > SIZE_MAX) {
+ git_error_set(GIT_ERROR_NOMEMORY, "blob is too large to blame");
+ error = -1;
+ goto cleanup;
+ }
+
blame->final_buf = git_blob_rawcontent(blame->final_blob);
- blame->final_buf_size = git_blob_rawsize(blame->final_blob);
+ blame->final_buf_size = (size_t)git_blob_rawsize(blame->final_blob);
ent = git__calloc(1, sizeof(git_blame__entry));
GIT_ERROR_CHECK_ALLOC(ent);
diff --git a/src/blame.h b/src/blame.h
index b31d2dc20..4141e2bb5 100644
--- a/src/blame.h
+++ b/src/blame.h
@@ -84,7 +84,7 @@ struct git_blame {
git_blame__entry *ent;
int num_lines;
const char *final_buf;
- git_off_t final_buf_size;
+ size_t final_buf_size;
};
git_blame *git_blame__alloc(
diff --git a/src/blob.c b/src/blob.c
index 487e608b7..5e734e2c1 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -25,18 +25,18 @@ const void *git_blob_rawcontent(const git_blob *blob)
return git_odb_object_data(blob->data.odb);
}
-git_off_t git_blob_rawsize(const git_blob *blob)
+git_object_size_t git_blob_rawsize(const git_blob *blob)
{
assert(blob);
if (blob->raw)
return blob->data.raw.size;
else
- return (git_off_t)git_odb_object_size(blob->data.odb);
+ return (git_object_size_t)git_odb_object_size(blob->data.odb);
}
int git_blob__getbuf(git_buf *buffer, git_blob *blob)
{
- git_off_t size = git_blob_rawsize(blob);
+ git_object_size_t size = git_blob_rawsize(blob);
GIT_ERROR_CHECK_BLOBSIZE(size);
return git_buf_set(buffer, git_blob_rawcontent(blob), (size_t)size);
@@ -91,13 +91,13 @@ int git_blob_create_from_buffer(
}
static int write_file_stream(
- git_oid *id, git_odb *odb, const char *path, git_off_t file_size)
+ git_oid *id, git_odb *odb, const char *path, git_object_size_t file_size)
{
int fd, error;
char buffer[FILEIO_BUFSIZE];
git_odb_stream *stream = NULL;
ssize_t read_len = -1;
- git_off_t written = 0;
+ git_object_size_t written = 0;
if ((error = git_odb_open_wstream(
&stream, odb, file_size, GIT_OBJECT_BLOB)) < 0)
@@ -129,7 +129,7 @@ static int write_file_stream(
static int write_file_filtered(
git_oid *id,
- git_off_t *size,
+ git_object_size_t *size,
git_odb *odb,
const char *full_path,
git_filter_list *fl)
@@ -184,7 +184,7 @@ int git_blob__create_from_paths(
int error;
struct stat st;
git_odb *odb = NULL;
- git_off_t size;
+ git_object_size_t size;
mode_t mode;
git_buf path = GIT_BUF_INIT;
@@ -389,7 +389,7 @@ cleanup:
int git_blob_is_binary(const git_blob *blob)
{
git_buf content = GIT_BUF_INIT;
- git_off_t size;
+ git_object_size_t size;
assert(blob);
diff --git a/src/blob.h b/src/blob.h
index 0d743ec2c..e5770991e 100644
--- a/src/blob.h
+++ b/src/blob.h
@@ -21,7 +21,7 @@ struct git_blob {
git_odb_object *odb;
struct {
const char *data;
- git_off_t size;
+ git_object_size_t size;
} raw;
} data;
unsigned int raw:1;
diff --git a/src/crlf.c b/src/crlf.c
index edccc0a42..81b5216bc 100644
--- a/src/crlf.c
+++ b/src/crlf.c
@@ -78,7 +78,7 @@ static int has_cr_in_index(const git_filter_source *src)
const git_index_entry *entry;
git_blob *blob;
const void *blobcontent;
- git_off_t blobsize;
+ git_object_size_t blobsize;
bool found_cr;
if (!path)
diff --git a/src/diff_file.c b/src/diff_file.c
index 978d7eaba..6c9a8e0ba 100644
--- a/src/diff_file.c
+++ b/src/diff_file.c
@@ -62,7 +62,7 @@ static int diff_file_content_init_common(
git_diff_driver_update_options(&fc->opts_flags, fc->driver);
/* make sure file is conceivable mmap-able */
- if ((git_off_t)((size_t)fc->file->size) != fc->file->size)
+ if ((size_t)fc->file->size != fc->file->size)
fc->file->flags |= GIT_DIFF_FLAG_BINARY;
/* check if user is forcing text diff the file */
else if (fc->opts_flags & GIT_DIFF_FORCE_TEXT) {
@@ -330,8 +330,10 @@ static int diff_file_content_load_workdir_file(
if (fd < 0)
return fd;
- if (!fc->file->size &&
- !(fc->file->size = git_futils_filesize(fd)))
+ if (!fc->file->size)
+ error = git_futils_filesize(&fc->file->size, fd);
+
+ if (error < 0 || !fc->file->size)
goto cleanup;
if ((diff_opts->flags & GIT_DIFF_SHOW_BINARY) == 0 &&
diff --git a/src/diff_file.h b/src/diff_file.h
index 5da7a7bb8..9354912be 100644
--- a/src/diff_file.h
+++ b/src/diff_file.h
@@ -20,7 +20,7 @@ typedef struct {
git_diff_driver *driver;
uint32_t flags;
uint32_t opts_flags;
- git_off_t opts_max_size;
+ git_object_size_t opts_max_size;
git_iterator_type_t src;
const git_blob *blob;
git_map map;
diff --git a/src/diff_generate.c b/src/diff_generate.c
index 7ec24d50d..bd0b71c81 100644
--- a/src/diff_generate.c
+++ b/src/diff_generate.c
@@ -560,11 +560,11 @@ int git_diff__oid_for_file(
git_diff *diff,
const char *path,
uint16_t mode,
- git_off_t size)
+ git_object_size_t size)
{
git_index_entry entry;
- if (size < 0 || size > UINT32_MAX) {
+ if (size > UINT32_MAX) {
git_error_set(GIT_ERROR_NOMEMORY, "file size overflow (for 32-bits) on '%s'", path);
return -1;
}
diff --git a/src/diff_generate.h b/src/diff_generate.h
index 6e669a3d5..5186d552c 100644
--- a/src/diff_generate.h
+++ b/src/diff_generate.h
@@ -88,7 +88,7 @@ extern int git_diff__oid_for_file(
git_diff *diff,
const char *path,
uint16_t mode,
- git_off_t size);
+ git_object_size_t size);
extern int git_diff__oid_for_entry(
git_oid *out,
@@ -120,7 +120,7 @@ GIT_INLINE(int) git_diff_file__resolve_zero_size(
git_odb_free(odb);
if (!error)
- file->size = (git_off_t)len;
+ file->size = (git_object_size_t)len;
return error;
}
diff --git a/src/diff_stats.c b/src/diff_stats.c
index a0681712f..19c9da05f 100644
--- a/src/diff_stats.c
+++ b/src/diff_stats.c
@@ -55,7 +55,7 @@ int git_diff_file_stats__full_to_buf(
{
const char *old_path = NULL, *new_path = NULL;
size_t padding;
- git_off_t old_size, new_size;
+ git_object_size_t old_size, new_size;
old_path = delta->old_file.path;
new_path = delta->new_file.path;
diff --git a/src/diff_tform.c b/src/diff_tform.c
index fc6012126..70bbb0048 100644
--- a/src/diff_tform.c
+++ b/src/diff_tform.c
@@ -510,7 +510,7 @@ static int similarity_sig(
if (file->size != git_blob_rawsize(info->blob))
file->size = git_blob_rawsize(info->blob);
- sz = (size_t)(git__is_sizet(file->size) ? file->size : -1);
+ sz = git__is_sizet(file->size) ? (size_t)file->size : (size_t)-1;
error = opts->metric->buffer_signature(
&cache[info->idx], info->file,
diff --git a/src/filter.c b/src/filter.c
index 7b7e7f172..bb9d66ad6 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -764,7 +764,7 @@ int git_filter_list_apply_to_file(
static int buf_from_blob(git_buf *out, git_blob *blob)
{
- git_off_t rawsize = git_blob_rawsize(blob);
+ git_object_size_t rawsize = git_blob_rawsize(blob);
if (!git__is_sizet(rawsize)) {
git_error_set(GIT_ERROR_OS, "blob is too large to filter");
diff --git a/src/futils.c b/src/futils.c
index 7454844e7..a7c360a1c 100644
--- a/src/futils.c
+++ b/src/futils.c
@@ -112,7 +112,7 @@ int git_futils_truncate(const char *path, int mode)
return 0;
}
-git_off_t git_futils_filesize(git_file fd)
+int git_futils_filesize(uint64_t *out, git_file fd)
{
struct stat sb;
@@ -121,7 +121,13 @@ git_off_t git_futils_filesize(git_file fd)
return -1;
}
- return sb.st_size;
+ if (sb.st_size < 0) {
+ git_error_set(GIT_ERROR_INVALID, "invalid file size");
+ return -1;
+ }
+
+ *out = sb.st_size;
+ return 0;
}
mode_t git_futils_canonical_mode(mode_t raw_mode)
@@ -301,7 +307,7 @@ int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmod
return 0;
}
-int git_futils_mmap_ro(git_map *out, git_file fd, git_off_t begin, size_t len)
+int git_futils_mmap_ro(git_map *out, git_file fd, off64_t begin, size_t len)
{
return p_mmap(out, len, GIT_PROT_READ, GIT_MAP_SHARED, fd, begin);
}
@@ -309,16 +315,14 @@ int git_futils_mmap_ro(git_map *out, git_file fd, git_off_t begin, size_t len)
int git_futils_mmap_ro_file(git_map *out, const char *path)
{
git_file fd = git_futils_open_ro(path);
- git_off_t len;
+ uint64_t len;
int result;
if (fd < 0)
return fd;
- if ((len = git_futils_filesize(fd)) < 0) {
- result = -1;
+ if ((result = git_futils_filesize(&len, fd)) < 0)
goto out;
- }
if (!git__is_sizet(len)) {
git_error_set(GIT_ERROR_OS, "file `%s` too large to mmap", path);
@@ -1106,7 +1110,7 @@ int git_futils_filestamp_check(
#if defined(GIT_USE_NSEC)
stamp->mtime.tv_nsec == st.st_mtime_nsec &&
#endif
- stamp->size == (git_off_t)st.st_size &&
+ stamp->size == (uint64_t)st.st_size &&
stamp->ino == (unsigned int)st.st_ino)
return 0;
@@ -1114,7 +1118,7 @@ int git_futils_filestamp_check(
#if defined(GIT_USE_NSEC)
stamp->mtime.tv_nsec = st.st_mtime_nsec;
#endif
- stamp->size = (git_off_t)st.st_size;
+ stamp->size = (uint64_t)st.st_size;
stamp->ino = (unsigned int)st.st_ino;
return 1;
@@ -1142,7 +1146,7 @@ void git_futils_filestamp_set_from_stat(
#else
stamp->mtime.tv_nsec = 0;
#endif
- stamp->size = (git_off_t)st->st_size;
+ stamp->size = (uint64_t)st->st_size;
stamp->ino = (unsigned int)st->st_ino;
} else {
memset(stamp, 0, sizeof(*stamp));
diff --git a/src/futils.h b/src/futils.h
index 1e2d3f9d9..3d5664679 100644
--- a/src/futils.h
+++ b/src/futils.h
@@ -255,7 +255,7 @@ extern int git_futils_truncate(const char *path, int mode);
/**
* Get the filesize in bytes of a file
*/
-extern git_off_t git_futils_filesize(git_file fd);
+extern int git_futils_filesize(uint64_t *out, git_file fd);
#define GIT_PERMS_IS_EXEC(MODE) (((MODE) & 0111) != 0)
#define GIT_PERMS_CANONICAL(MODE) (GIT_PERMS_IS_EXEC(MODE) ? 0755 : 0644)
@@ -290,7 +290,7 @@ extern mode_t git_futils_canonical_mode(mode_t raw_mode);
extern int git_futils_mmap_ro(
git_map *out,
git_file fd,
- git_off_t begin,
+ off64_t begin,
size_t len);
/**
@@ -330,7 +330,7 @@ extern int git_futils_fake_symlink(const char *new, const char *old);
*/
typedef struct {
struct timespec mtime;
- git_off_t size;
+ uint64_t size;
unsigned int ino;
} git_futils_filestamp;
diff --git a/src/indexer.c b/src/indexer.c
index 84b950d13..717549fa2 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -47,8 +47,8 @@ struct git_indexer {
struct git_pack_header hdr;
struct git_pack_file *pack;
unsigned int mode;
- git_off_t off;
- git_off_t entry_start;
+ off64_t off;
+ off64_t entry_start;
git_object_t entry_type;
git_buf entry_data;
git_packfile_stream stream;
@@ -75,7 +75,7 @@ struct git_indexer {
};
struct delta_info {
- git_off_t delta_off;
+ off64_t delta_off;
};
const git_oid *git_indexer_hash(const git_indexer *idx)
@@ -220,7 +220,7 @@ static int store_delta(git_indexer *idx)
return 0;
}
-static int hash_header(git_hash_ctx *ctx, git_off_t len, git_object_t type)
+static int hash_header(git_hash_ctx *ctx, off64_t len, git_object_t type)
{
char buffer[64];
size_t hdrlen;
@@ -265,7 +265,7 @@ static int advance_delta_offset(git_indexer *idx, git_object_t type)
if (type == GIT_OBJECT_REF_DELTA) {
idx->off += GIT_OID_RAWSZ;
} else {
- git_off_t base_off = get_delta_base(idx->pack, &w, &idx->off, type, idx->entry_start);
+ off64_t base_off = get_delta_base(idx->pack, &w, &idx->off, type, idx->entry_start);
git_mwindow_close(&w);
if (base_off < 0)
return (int)base_off;
@@ -291,7 +291,7 @@ static int read_object_stream(git_indexer *idx, git_packfile_stream *stream)
return 0;
}
-static int crc_object(uint32_t *crc_out, git_mwindow_file *mwf, git_off_t start, git_off_t size)
+static int crc_object(uint32_t *crc_out, git_mwindow_file *mwf, off64_t start, off64_t size)
{
void *ptr;
uint32_t crc;
@@ -414,9 +414,9 @@ static int store_object(git_indexer *idx)
int i, error;
git_oid oid;
struct entry *entry;
- git_off_t entry_size;
+ off64_t entry_size;
struct git_pack_entry *pentry;
- git_off_t entry_start = idx->entry_start;
+ off64_t entry_start = idx->entry_start;
entry = git__calloc(1, sizeof(*entry));
GIT_ERROR_CHECK_ALLOC(entry);
@@ -485,7 +485,7 @@ GIT_INLINE(bool) has_entry(git_indexer *idx, git_oid *id)
return git_oidmap_exists(idx->pack->idx_cache, id);
}
-static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_entry *pentry, git_off_t entry_start)
+static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_entry *pentry, off64_t entry_start)
{
int i;
@@ -515,7 +515,7 @@ static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_ent
return 0;
}
-static int hash_and_save(git_indexer *idx, git_rawobj *obj, git_off_t entry_start)
+static int hash_and_save(git_indexer *idx, git_rawobj *obj, off64_t entry_start)
{
git_oid oid;
size_t entry_size;
@@ -596,12 +596,12 @@ static void hash_partially(git_indexer *idx, const uint8_t *data, size_t size)
idx->inbuf_len += size - to_expell;
}
-static int write_at(git_indexer *idx, const void *data, git_off_t offset, size_t size)
+static int write_at(git_indexer *idx, const void *data, off64_t offset, size_t size)
{
git_file fd = idx->pack->mwf.fd;
size_t mmap_alignment;
size_t page_offset;
- git_off_t page_start;
+ off64_t page_start;
unsigned char *map_data;
git_map map;
int error;
@@ -627,11 +627,11 @@ static int write_at(git_indexer *idx, const void *data, git_off_t offset, size_t
static int append_to_pack(git_indexer *idx, const void *data, size_t size)
{
- git_off_t new_size;
+ off64_t new_size;
size_t mmap_alignment;
size_t page_offset;
- git_off_t page_start;
- git_off_t current_size = idx->pack->mwf.size;
+ off64_t page_start;
+ off64_t current_size = idx->pack->mwf.size;
int fd = idx->pack->mwf.fd;
int error;
@@ -661,7 +661,7 @@ static int append_to_pack(git_indexer *idx, const void *data, size_t size)
static int read_stream_object(git_indexer *idx, git_indexer_progress *stats)
{
git_packfile_stream *stream = &idx->stream;
- git_off_t entry_start = idx->off;
+ off64_t entry_start = idx->off;
size_t entry_size;
git_object_t type;
git_mwindow *w = NULL;
@@ -865,7 +865,7 @@ static int inject_object(git_indexer *idx, git_oid *id)
git_oid foo = {{0}};
unsigned char hdr[64];
git_buf buf = GIT_BUF_INIT;
- git_off_t entry_start;
+ off64_t entry_start;
const void *data;
size_t len, hdr_len;
int error;
@@ -939,7 +939,7 @@ static int fix_thin_pack(git_indexer *idx, git_indexer_progress *stats)
size_t size;
git_object_t type;
git_mwindow *w = NULL;
- git_off_t curpos = 0;
+ off64_t curpos = 0;
unsigned char *base_info;
unsigned int left = 0;
git_oid base;
@@ -1054,7 +1054,7 @@ static int update_header_and_rehash(git_indexer *idx, git_indexer_progress *stat
{
void *ptr;
size_t chunk = 1024*1024;
- git_off_t hashed = 0;
+ off64_t hashed = 0;
git_mwindow *w = NULL;
git_mwindow_file *mwf;
unsigned int left;
diff --git a/src/integer.h b/src/integer.h
index e024a86d3..067c0be1f 100644
--- a/src/integer.h
+++ b/src/integer.h
@@ -8,10 +8,10 @@
#define INCLUDE_integer_h__
/** @return true if p fits into the range of a size_t */
-GIT_INLINE(int) git__is_sizet(git_off_t p)
+GIT_INLINE(int) git__is_sizet(int64_t p)
{
size_t r = (size_t)p;
- return p == (git_off_t)r;
+ return p == (int64_t)r;
}
/** @return true if p fits into the range of an ssize_t */
@@ -36,10 +36,10 @@ GIT_INLINE(int) git__is_uint32(size_t p)
}
/** @return true if p fits into the range of an unsigned long */
-GIT_INLINE(int) git__is_ulong(git_off_t p)
+GIT_INLINE(int) git__is_ulong(int64_t p)
{
unsigned long r = (unsigned long)p;
- return p == (git_off_t)r;
+ return p == (int64_t)r;
}
/** @return true if p fits into the range of an int */
diff --git a/src/map.h b/src/map.h
index 2009c3ab5..6328d8cf4 100644
--- a/src/map.h
+++ b/src/map.h
@@ -40,7 +40,7 @@ typedef struct { /* memory mapped buffer */
assert((prot & GIT_PROT_WRITE) || (prot & GIT_PROT_READ)); \
assert((flags & GIT_MAP_FIXED) == 0); } while (0)
-extern int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset);
+extern int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset);
extern int p_munmap(git_map *map);
#endif
diff --git a/src/merge.c b/src/merge.c
index b72b3843b..05a776e45 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -1024,7 +1024,7 @@ static int index_entry_similarity_calc(
{
git_blob *blob;
git_diff_file diff_file = {{{0}}};
- git_off_t blobsize;
+ git_object_size_t blobsize;
int error;
*out = NULL;
diff --git a/src/mwindow.c b/src/mwindow.c
index e834f7621..262786a5f 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -167,11 +167,11 @@ void git_mwindow_free_all_locked(git_mwindow_file *mwf)
/*
* Check if a window 'win' contains the address 'offset'
*/
-int git_mwindow_contains(git_mwindow *win, git_off_t offset)
+int git_mwindow_contains(git_mwindow *win, off64_t offset)
{
- git_off_t win_off = win->offset;
+ off64_t win_off = win->offset;
return win_off <= offset
- && offset <= (git_off_t)(win_off + win->window_map.len);
+ && offset <= (off64_t)(win_off + win->window_map.len);
}
/*
@@ -246,12 +246,12 @@ static int git_mwindow_close_lru(git_mwindow_file *mwf)
static git_mwindow *new_window(
git_mwindow_file *mwf,
git_file fd,
- git_off_t size,
- git_off_t offset)
+ off64_t size,
+ off64_t offset)
{
git_mwindow_ctl *ctl = &mem_ctl;
size_t walign = git_mwindow__window_size / 2;
- git_off_t len;
+ off64_t len;
git_mwindow *w;
w = git__malloc(sizeof(*w));
@@ -263,8 +263,8 @@ static git_mwindow *new_window(
w->offset = (offset / walign) * walign;
len = size - w->offset;
- if (len > (git_off_t)git_mwindow__window_size)
- len = (git_off_t)git_mwindow__window_size;
+ if (len > (off64_t)git_mwindow__window_size)
+ len = (off64_t)git_mwindow__window_size;
ctl->mapped += (size_t)len;
@@ -311,7 +311,7 @@ static git_mwindow *new_window(
unsigned char *git_mwindow_open(
git_mwindow_file *mwf,
git_mwindow **cursor,
- git_off_t offset,
+ off64_t offset,
size_t extra,
unsigned int *left)
{
diff --git a/src/mwindow.h b/src/mwindow.h
index ea962d1b6..1a391b055 100644
--- a/src/mwindow.h
+++ b/src/mwindow.h
@@ -16,7 +16,7 @@
typedef struct git_mwindow {
struct git_mwindow *next;
git_map window_map;
- git_off_t offset;
+ off64_t offset;
size_t last_used;
size_t inuse_cnt;
} git_mwindow;
@@ -24,7 +24,7 @@ typedef struct git_mwindow {
typedef struct git_mwindow_file {
git_mwindow *windows;
int fd;
- git_off_t size;
+ off64_t size;
} git_mwindow_file;
typedef struct git_mwindow_ctl {
@@ -37,10 +37,10 @@ typedef struct git_mwindow_ctl {
git_vector windowfiles;
} git_mwindow_ctl;
-int git_mwindow_contains(git_mwindow *win, git_off_t offset);
+int git_mwindow_contains(git_mwindow *win, off64_t offset);
void git_mwindow_free_all(git_mwindow_file *mwf); /* locks */
void git_mwindow_free_all_locked(git_mwindow_file *mwf); /* run under lock */
-unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor, git_off_t offset, size_t extra, unsigned int *left);
+unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor, off64_t offset, size_t extra, unsigned int *left);
int git_mwindow_file_register(git_mwindow_file *mwf);
void git_mwindow_file_deregister(git_mwindow_file *mwf);
void git_mwindow_close(git_mwindow **w_cursor);
diff --git a/src/notes.c b/src/notes.c
index 5028107d2..4633a16ea 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -320,7 +320,7 @@ static int note_new(
git_blob *blob)
{
git_note *note = NULL;
- git_off_t blobsize;
+ git_object_size_t blobsize;
note = git__malloc(sizeof(git_note));
GIT_ERROR_CHECK_ALLOC(note);
diff --git a/src/object.h b/src/object.h
index 227a6fdd5..4b6793612 100644
--- a/src/object.h
+++ b/src/object.h
@@ -11,6 +11,8 @@
#include "repository.h"
+#define GIT_OBJECT_SIZE_MAX UINT64_MAX
+
extern bool git_object__strict_input_validation;
/** Base git object for inheritance */
diff --git a/src/odb.c b/src/odb.c
index 06e4930b0..68d9a9a3f 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -89,7 +89,7 @@ int git_odb__format_object_header(
size_t *written,
char *hdr,
size_t hdr_size,
- git_off_t obj_len,
+ git_object_size_t obj_len,
git_object_t obj_type)
{
const char *type_str = git_object_type2string(obj_type);
@@ -320,20 +320,26 @@ int git_odb__hashlink(git_oid *out, const char *path)
int git_odb_hashfile(git_oid *out, const char *path, git_object_t type)
{
- git_off_t size;
- int result, fd = git_futils_open_ro(path);
- if (fd < 0)
+ uint64_t size;
+ int fd, error = 0;
+
+ if ((fd = git_futils_open_ro(path)) < 0)
return fd;
- if ((size = git_futils_filesize(fd)) < 0 || !git__is_sizet(size)) {
+ if ((error = git_futils_filesize(&size, fd)) < 0)
+ goto done;
+
+ if (!git__is_sizet(size)) {
git_error_set(GIT_ERROR_OS, "file size overflow for 32-bit systems");
- p_close(fd);
- return -1;
+ error = -1;
+ goto done;
}
- result = git_odb__hashfd(out, fd, (size_t)size, type);
+ error = git_odb__hashfd(out, fd, (size_t)size, type);
+
+done:
p_close(fd);
- return result;
+ return error;
}
int git_odb_hash(git_oid *id, const void *data, size_t len, git_object_t type)
@@ -385,7 +391,7 @@ static void fake_wstream__free(git_odb_stream *_stream)
git__free(stream);
}
-static int init_fake_wstream(git_odb_stream **stream_p, git_odb_backend *backend, git_off_t size, git_object_t type)
+static int init_fake_wstream(git_odb_stream **stream_p, git_odb_backend *backend, git_object_size_t size, git_object_t type)
{
fake_wstream *stream;
size_t blobsize;
@@ -1319,7 +1325,7 @@ int git_odb_write(
return error;
}
-static int hash_header(git_hash_ctx *ctx, git_off_t size, git_object_t type)
+static int hash_header(git_hash_ctx *ctx, git_object_size_t size, git_object_t type)
{
char header[64];
size_t hdrlen;
@@ -1333,7 +1339,7 @@ static int hash_header(git_hash_ctx *ctx, git_off_t size, git_object_t type)
}
int git_odb_open_wstream(
- git_odb_stream **stream, git_odb *db, git_off_t size, git_object_t type)
+ git_odb_stream **stream, git_odb *db, git_object_size_t size, git_object_t type)
{
size_t i, writes = 0;
int error = GIT_ERROR;
diff --git a/src/odb.h b/src/odb.h
index 79ed6b402..8dd4efd64 100644
--- a/src/odb.h
+++ b/src/odb.h
@@ -70,7 +70,7 @@ int git_odb__hashobj(git_oid *id, git_rawobj *obj);
/*
* Format the object header such as it would appear in the on-disk object
*/
-int git_odb__format_object_header(size_t *out_len, char *hdr, size_t hdr_size, git_off_t obj_len, git_object_t obj_type);
+int git_odb__format_object_header(size_t *out_len, char *hdr, size_t hdr_size, git_object_size_t obj_len, git_object_t obj_type);
/*
* Hash an open file descriptor.
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 04b81653b..4a54b3fc0 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -824,7 +824,7 @@ static int filebuf_flags(loose_backend *backend)
return flags;
}
-static int loose_backend__writestream(git_odb_stream **stream_out, git_odb_backend *_backend, git_off_t length, git_object_t type)
+static int loose_backend__writestream(git_odb_stream **stream_out, git_odb_backend *_backend, git_object_size_t length, git_object_t type)
{
loose_backend *backend;
loose_writestream *stream = NULL;
@@ -833,7 +833,7 @@ static int loose_backend__writestream(git_odb_stream **stream_out, git_odb_backe
size_t hdrlen;
int error;
- assert(_backend && length >= 0);
+ assert(_backend);
backend = (loose_backend *)_backend;
*stream_out = NULL;
diff --git a/src/offmap.c b/src/offmap.c
index ba86bc0d0..be9eb66d8 100644
--- a/src/offmap.c
+++ b/src/offmap.c
@@ -14,9 +14,9 @@
#define kfree git__free
#include "khash.h"
-__KHASH_TYPE(off, git_off_t, void *)
+__KHASH_TYPE(off, off64_t, void *)
-__KHASH_IMPL(off, static kh_inline, git_off_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal)
+__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal)
int git_offmap_new(git_offmap **out)
@@ -42,7 +42,7 @@ size_t git_offmap_size(git_offmap *map)
return kh_size(map);
}
-void *git_offmap_get(git_offmap *map, const git_off_t key)
+void *git_offmap_get(git_offmap *map, const off64_t key)
{
size_t idx = kh_get(off, map, key);
if (idx == kh_end(map) || !kh_exist(map, idx))
@@ -50,7 +50,7 @@ void *git_offmap_get(git_offmap *map, const git_off_t key)
return kh_val(map, idx);
}
-int git_offmap_set(git_offmap *map, const git_off_t key, void *value)
+int git_offmap_set(git_offmap *map, const off64_t key, void *value)
{
size_t idx;
int rval;
@@ -67,7 +67,7 @@ int git_offmap_set(git_offmap *map, const git_off_t key, void *value)
return 0;
}
-int git_offmap_delete(git_offmap *map, const git_off_t key)
+int git_offmap_delete(git_offmap *map, const off64_t key)
{
khiter_t idx = kh_get(off, map, key);
if (idx == kh_end(map))
@@ -76,12 +76,12 @@ int git_offmap_delete(git_offmap *map, const git_off_t key)
return 0;
}
-int git_offmap_exists(git_offmap *map, const git_off_t key)
+int git_offmap_exists(git_offmap *map, const off64_t key)
{
return kh_get(off, map, key) != kh_end(map);
}
-int git_offmap_iterate(void **value, git_offmap *map, size_t *iter, git_off_t *key)
+int git_offmap_iterate(void **value, git_offmap *map, size_t *iter, off64_t *key)
{
size_t i = *iter;
diff --git a/src/offmap.h b/src/offmap.h
index 6fa7d2f8f..81c459b01 100644
--- a/src/offmap.h
+++ b/src/offmap.h
@@ -11,11 +11,11 @@
#include "git2/types.h"
-/** A map with `git_off_t`s as key. */
+/** A map with `off64_t`s as key. */
typedef struct kh_off_s git_offmap;
/**
- * Allocate a new `git_off_t` map.
+ * Allocate a new `off64_t` map.
*
* @param out Pointer to the map that shall be allocated.
* @return 0 on success, an error code if allocation has failed.
@@ -59,7 +59,7 @@ size_t git_offmap_size(git_offmap *map);
* @param key key to search for
* @return value associated with the given key or NULL if the key was not found
*/
-void *git_offmap_get(git_offmap *map, const git_off_t key);
+void *git_offmap_get(git_offmap *map, const off64_t key);
/**
* Set the entry for key to value.
@@ -74,7 +74,7 @@ void *git_offmap_get(git_offmap *map, const git_off_t key);
* @return zero if the key was successfully set, a negative error
* code otherwise
*/
-int git_offmap_set(git_offmap *map, const git_off_t key, void *value);
+int git_offmap_set(git_offmap *map, const off64_t key, void *value);
/**
* Delete an entry from the map.
@@ -88,7 +88,7 @@ int git_offmap_set(git_offmap *map, const git_off_t key, void *value);
* such key was found, a negative code in case of an
* error
*/
-int git_offmap_delete(git_offmap *map, const git_off_t key);
+int git_offmap_delete(git_offmap *map, const off64_t key);
/**
* Check whether a key exists in the given map.
@@ -97,7 +97,7 @@ int git_offmap_delete(git_offmap *map, const git_off_t key);
* @param key key to search for
* @return 0 if the key has not been found, 1 otherwise
*/
-int git_offmap_exists(git_offmap *map, const git_off_t key);
+int git_offmap_exists(git_offmap *map, const off64_t key);
/**
* Iterate over entries of the map.
@@ -118,7 +118,7 @@ int git_offmap_exists(git_offmap *map, const git_off_t key);
* GIT_ITEROVER if no entries are left. A negative error
* code otherwise.
*/
-int git_offmap_iterate(void **value, git_offmap *map, size_t *iter, git_off_t *key);
+int git_offmap_iterate(void **value, git_offmap *map, size_t *iter, off64_t *key);
#define git_offmap_foreach(h, kvar, vvar, code) { size_t __i = 0; \
while (git_offmap_iterate((void **) &(vvar), h, &__i, &(kvar)) == 0) { \
diff --git a/src/pack-objects.h b/src/pack-objects.h
index 53684a1ba..04514daa6 100644
--- a/src/pack-objects.h
+++ b/src/pack-objects.h
@@ -30,7 +30,7 @@
typedef struct git_pobject {
git_oid id;
git_object_t type;
- git_off_t offset;
+ off64_t offset;
size_t size;
diff --git a/src/pack.c b/src/pack.c
index 68eeb7b0d..4c4eb9b8e 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -20,12 +20,12 @@
bool git_disable_pack_keep_file_checks = false;
static int packfile_open(struct git_pack_file *p);
-static git_off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n);
+static off64_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n);
static int packfile_unpack_compressed(
git_rawobj *obj,
struct git_pack_file *p,
git_mwindow **w_curs,
- git_off_t *curpos,
+ off64_t *curpos,
size_t size,
git_object_t type);
@@ -37,7 +37,7 @@ static int packfile_unpack_compressed(
* GIT_OID_MINPREFIXLEN and GIT_OID_HEXSZ.
*/
static int pack_entry_find_offset(
- git_off_t *offset_out,
+ off64_t *offset_out,
git_oid *found_oid,
struct git_pack_file *p,
const git_oid *short_oid,
@@ -109,7 +109,7 @@ static int cache_init(git_pack_cache *cache)
return 0;
}
-static git_pack_cache_entry *cache_get(git_pack_cache *cache, git_off_t offset)
+static git_pack_cache_entry *cache_get(git_pack_cache *cache, off64_t offset)
{
git_pack_cache_entry *entry;
@@ -128,7 +128,7 @@ static git_pack_cache_entry *cache_get(git_pack_cache *cache, git_off_t offset)
/* Run with the cache lock held */
static void free_lowest_entry(git_pack_cache *cache)
{
- git_off_t offset;
+ off64_t offset;
git_pack_cache_entry *entry;
git_offmap_foreach(cache->entries, offset, entry, {
@@ -144,7 +144,7 @@ static int cache_add(
git_pack_cache_entry **cached_out,
git_pack_cache *cache,
git_rawobj *base,
- git_off_t offset)
+ off64_t offset)
{
git_pack_cache_entry *entry;
int exists;
@@ -345,7 +345,7 @@ static int pack_index_open(struct git_pack_file *p)
static unsigned char *pack_window_open(
struct git_pack_file *p,
git_mwindow **w_cursor,
- git_off_t offset,
+ off64_t offset,
unsigned int *left)
{
if (p->mwf.fd == -1 && packfile_open(p) < 0)
@@ -441,7 +441,7 @@ int git_packfile_unpack_header(
git_object_t *type_p,
git_mwindow_file *mwf,
git_mwindow **w_curs,
- git_off_t *curpos)
+ off64_t *curpos)
{
unsigned char *base;
unsigned int left;
@@ -474,13 +474,13 @@ int git_packfile_resolve_header(
size_t *size_p,
git_object_t *type_p,
struct git_pack_file *p,
- git_off_t offset)
+ off64_t offset)
{
git_mwindow *w_curs = NULL;
- git_off_t curpos = offset;
+ off64_t curpos = offset;
size_t size;
git_object_t type;
- git_off_t base_offset;
+ off64_t base_offset;
int error;
error = git_packfile_unpack_header(&size, &type, &p->mwf, &w_curs, &curpos);
@@ -528,13 +528,13 @@ int git_packfile_resolve_header(
* cache, we stop calculating there.
*/
static int pack_dependency_chain(git_dependency_chain *chain_out,
- git_pack_cache_entry **cached_out, git_off_t *cached_off,
+ git_pack_cache_entry **cached_out, off64_t *cached_off,
struct pack_chain_elem *small_stack, size_t *stack_sz,
- struct git_pack_file *p, git_off_t obj_offset)
+ struct git_pack_file *p, off64_t obj_offset)
{
git_dependency_chain chain = GIT_ARRAY_INIT;
git_mwindow *w_curs = NULL;
- git_off_t curpos = obj_offset, base_offset;
+ off64_t curpos = obj_offset, base_offset;
int error = 0, use_heap = 0;
size_t size, elem_pos;
git_object_t type;
@@ -619,10 +619,10 @@ on_error:
int git_packfile_unpack(
git_rawobj *obj,
struct git_pack_file *p,
- git_off_t *obj_offset)
+ off64_t *obj_offset)
{
git_mwindow *w_curs = NULL;
- git_off_t curpos = *obj_offset;
+ off64_t curpos = *obj_offset;
int error, free_base = 0;
git_dependency_chain chain = GIT_ARRAY_INIT;
struct pack_chain_elem *elem = NULL, *stack;
@@ -777,7 +777,7 @@ static void use_git_free(void *opaq, void *ptr)
git__free(ptr);
}
-int git_packfile_stream_open(git_packfile_stream *obj, struct git_pack_file *p, git_off_t curpos)
+int git_packfile_stream_open(git_packfile_stream *obj, struct git_pack_file *p, off64_t curpos)
{
int st;
@@ -846,7 +846,7 @@ static int packfile_unpack_compressed(
git_rawobj *obj,
struct git_pack_file *p,
git_mwindow **w_curs,
- git_off_t *curpos,
+ off64_t *curpos,
size_t size,
git_object_t type)
{
@@ -909,16 +909,16 @@ static int packfile_unpack_compressed(
* curpos is where the data starts, delta_obj_offset is the where the
* header starts
*/
-git_off_t get_delta_base(
+off64_t get_delta_base(
struct git_pack_file *p,
git_mwindow **w_curs,
- git_off_t *curpos,
+ off64_t *curpos,
git_object_t type,
- git_off_t delta_obj_offset)
+ off64_t delta_obj_offset)
{
unsigned int left = 0;
unsigned char *base_info;
- git_off_t base_offset;
+ off64_t base_offset;
git_oid unused;
base_info = pack_window_open(p, w_curs, *curpos, &left);
@@ -1045,7 +1045,7 @@ static int packfile_open(struct git_pack_file *p)
if (!p->mwf.size) {
if (!S_ISREG(st.st_mode))
goto cleanup;
- p->mwf.size = (git_off_t)st.st_size;
+ p->mwf.size = (off64_t)st.st_size;
} else if (p->mwf.size != st.st_size)
goto cleanup;
@@ -1182,7 +1182,7 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path)
*
***********************************************************/
-static git_off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n)
+static off64_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n)
{
const unsigned char *index = p->index_map.data;
const unsigned char *end = index + p->index_map.len;
@@ -1270,7 +1270,7 @@ int git_pack_foreach_entry(
}
static int pack_entry_find_offset(
- git_off_t *offset_out,
+ off64_t *offset_out,
git_oid *found_oid,
struct git_pack_file *p,
const git_oid *short_oid,
@@ -1280,7 +1280,7 @@ static int pack_entry_find_offset(
const unsigned char *index;
unsigned hi, lo, stride;
int pos, found = 0;
- git_off_t offset;
+ off64_t offset;
const unsigned char *current = 0;
*offset_out = 0;
@@ -1375,7 +1375,7 @@ int git_pack_entry_find(
const git_oid *short_oid,
size_t len)
{
- git_off_t offset;
+ off64_t offset;
git_oid found_oid;
int error;
diff --git a/src/pack.h b/src/pack.h
index 483c4e8d7..a294ecd17 100644
--- a/src/pack.h
+++ b/src/pack.h
@@ -64,8 +64,8 @@ typedef struct git_pack_cache_entry {
} git_pack_cache_entry;
struct pack_chain_elem {
- git_off_t base_key;
- git_off_t offset;
+ off64_t base_key;
+ off64_t offset;
size_t size;
git_object_t type;
};
@@ -108,13 +108,13 @@ struct git_pack_file {
};
struct git_pack_entry {
- git_off_t offset;
+ off64_t offset;
git_oid sha1;
struct git_pack_file *p;
};
typedef struct git_packfile_stream {
- git_off_t curpos;
+ off64_t curpos;
int done;
z_stream zstream;
struct git_pack_file *p;
@@ -130,23 +130,23 @@ int git_packfile_unpack_header(
git_object_t *type_p,
git_mwindow_file *mwf,
git_mwindow **w_curs,
- git_off_t *curpos);
+ off64_t *curpos);
int git_packfile_resolve_header(
size_t *size_p,
git_object_t *type_p,
struct git_pack_file *p,
- git_off_t offset);
+ off64_t offset);
-int git_packfile_unpack(git_rawobj *obj, struct git_pack_file *p, git_off_t *obj_offset);
+int git_packfile_unpack(git_rawobj *obj, struct git_pack_file *p, off64_t *obj_offset);
-int git_packfile_stream_open(git_packfile_stream *obj, struct git_pack_file *p, git_off_t curpos);
+int git_packfile_stream_open(git_packfile_stream *obj, struct git_pack_file *p, off64_t curpos);
ssize_t git_packfile_stream_read(git_packfile_stream *obj, void *buffer, size_t len);
void git_packfile_stream_dispose(git_packfile_stream *obj);
-git_off_t get_delta_base(struct git_pack_file *p, git_mwindow **w_curs,
- git_off_t *curpos, git_object_t type,
- git_off_t delta_obj_offset);
+off64_t get_delta_base(struct git_pack_file *p, git_mwindow **w_curs,
+ off64_t *curpos, git_object_t type,
+ off64_t delta_obj_offset);
void git_packfile_close(struct git_pack_file *p, bool unlink_packfile);
void git_packfile_free(struct git_pack_file *p);
diff --git a/src/patch_parse.c b/src/patch_parse.c
index e4031f11d..35fd65a0d 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -491,7 +491,7 @@ done:
static int parse_int(int *out, git_patch_parse_ctx *ctx)
{
- git_off_t num;
+ int64_t num;
if (git_parse_advance_digit(&num, &ctx->parse_ctx, 10) < 0 || !git__is_int(num))
return -1;
@@ -765,7 +765,7 @@ static int parse_patch_binary_side(
{
git_diff_binary_t type = GIT_DIFF_BINARY_NONE;
git_buf base85 = GIT_BUF_INIT, decoded = GIT_BUF_INIT;
- git_off_t len;
+ int64_t len;
int error = 0;
if (git_parse_ctx_contains_s(&ctx->parse_ctx, "literal ")) {
diff --git a/src/posix.c b/src/posix.c
index 1ea2ce54b..fbaa7c3ca 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -235,7 +235,7 @@ int git__mmap_alignment(size_t *alignment)
}
-int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
+int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset)
{
GIT_MMAP_VALIDATE(out, len, prot, flags);
diff --git a/src/posix.h b/src/posix.h
index 170ff2606..eef667762 100644
--- a/src/posix.h
+++ b/src/posix.h
@@ -89,6 +89,18 @@
#define EAFNOSUPPORT (INT_MAX-1)
#endif
+/* Provide a 64-bit size for offsets. */
+
+#if defined(_MSC_VER)
+typedef __int64 off64_t;
+#elif defined(__HAIKU__)
+typedef __haiku_std_int64 off64_t;
+#elif defined(__APPLE__)
+typedef __int64_t off64_t;
+#else
+typedef int64_t off64_t;
+#endif
+
typedef int git_file;
/**
diff --git a/src/reader.c b/src/reader.c
index 2d87251ee..90f700a00 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -32,7 +32,7 @@ static int tree_reader_read(
tree_reader *reader = (tree_reader *)_reader;
git_tree_entry *tree_entry = NULL;
git_blob *blob = NULL;
- git_off_t blobsize;
+ git_object_size_t blobsize;
int error;
if ((error = git_tree_entry_bypath(&tree_entry, reader->tree, filename)) < 0 ||
diff --git a/src/repository.c b/src/repository.c
index 5871e9567..14968d75d 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -2545,7 +2545,7 @@ int git_repository_hashfile(
int error;
git_filter_list *fl = NULL;
git_file fd = -1;
- git_off_t len;
+ uint64_t len;
git_buf full_path = GIT_BUF_INIT;
assert(out && path && repo); /* as_path can be NULL */
@@ -2582,11 +2582,8 @@ int git_repository_hashfile(
goto cleanup;
}
- len = git_futils_filesize(fd);
- if (len < 0) {
- error = (int)len;
+ if ((error = git_futils_filesize(&len, fd)) < 0)
goto cleanup;
- }
if (!git__is_sizet(len)) {
git_error_set(GIT_ERROR_OS, "file size overflow for 32-bit systems");
diff --git a/src/unix/map.c b/src/unix/map.c
index 1ebbced5c..7f9076e19 100644
--- a/src/unix/map.c
+++ b/src/unix/map.c
@@ -32,7 +32,7 @@ int git__mmap_alignment(size_t *alignment)
return git__page_size(alignment);
}
-int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
+int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset)
{
int mprot = PROT_READ;
int mflag = 0;
diff --git a/src/win32/map.c b/src/win32/map.c
index 5769cb869..e2ce737de 100644
--- a/src/win32/map.c
+++ b/src/win32/map.c
@@ -50,7 +50,7 @@ int git__mmap_alignment(size_t *page_size)
return 0;
}
-int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
+int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset)
{
HANDLE fh = (HANDLE)_get_osfhandle(fd);
DWORD alignment = get_allocation_granularity();
@@ -58,8 +58,8 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
DWORD view_prot = 0;
DWORD off_low = 0;
DWORD off_hi = 0;
- git_off_t page_start;
- git_off_t page_offset;
+ off64_t page_start;
+ off64_t page_offset;
GIT_MMAP_VALIDATE(out, len, prot, flags);
@@ -99,8 +99,6 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
return -1;
}
- assert(sizeof(git_off_t) == 8);
-
off_low = (DWORD)(page_start);
off_hi = (DWORD)(page_start >> 32);
out->data = MapViewOfFile(out->fmh, view_prot, off_hi, off_low, len);
diff --git a/src/win32/posix.h b/src/win32/posix.h
index e427d64c3..f115088b4 100644
--- a/src/win32/posix.h
+++ b/src/win32/posix.h
@@ -47,7 +47,7 @@ extern int p_chdir(const char* path);
extern int p_chmod(const char* path, mode_t mode);
extern int p_rmdir(const char* path);
extern int p_access(const char* path, mode_t mode);
-extern int p_ftruncate(int fd, git_off_t size);
+extern int p_ftruncate(int fd, off64_t size);
/* p_lstat is almost but not quite POSIX correct. Specifically, the use of
* ENOTDIR is wrong, in that it does not mean precisely that a non-directory
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 078b50952..2bc93a3c7 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -210,7 +210,7 @@ on_error:
* We now take a "git_off_t" rather than "long" because
* files may be longer than 2Gb.
*/
-int p_ftruncate(int fd, git_off_t size)
+int p_ftruncate(int fd, off64_t size)
{
if (size < 0) {
errno = EINVAL;
diff --git a/src/win32/w32_util.h b/src/win32/w32_util.h
index ac191157c..d7f9d3da6 100644
--- a/src/win32/w32_util.h
+++ b/src/win32/w32_util.h
@@ -120,7 +120,7 @@ GIT_INLINE(void) git_win32__stat_init(
st->st_uid = 0;
st->st_nlink = 1;
st->st_mode = mode;
- st->st_size = ((git_off_t)nFileSizeHigh << 32) + nFileSizeLow;
+ st->st_size = ((int64_t)nFileSizeHigh << 32) + nFileSizeLow;
st->st_dev = _getdrive() - 1;
st->st_rdev = st->st_dev;
git_win32__filetime_to_timespec(&ftLastAccessTime, &(st->st_atim));
diff --git a/tests/core/ftruncate.c b/tests/core/ftruncate.c
index 2f4729fc2..0c731cb1e 100644
--- a/tests/core/ftruncate.c
+++ b/tests/core/ftruncate.c
@@ -27,7 +27,7 @@ void test_core_ftruncate__cleanup(void)
p_unlink(filename);
}
-static void _extend(git_off_t i64len)
+static void _extend(off64_t i64len)
{
struct stat st;
int error;
diff --git a/tests/index/tests.c b/tests/index/tests.c
index 2d2744df1..1164cba0e 100644
--- a/tests/index/tests.c
+++ b/tests/index/tests.c
@@ -13,7 +13,7 @@ static const size_t index_entry_count_2 = 1437;
struct test_entry {
size_t index;
char path[128];
- git_off_t file_size;
+ off64_t file_size;
git_time_t mtime;
};
diff --git a/tests/object/blob/filter.c b/tests/object/blob/filter.c
index 45dbc9263..0f0f4845f 100644
--- a/tests/object/blob/filter.c
+++ b/tests/object/blob/filter.c
@@ -19,7 +19,7 @@ static const char *g_crlf_raw[CRLF_NUM_TEST_OBJECTS] = {
"\xFE\xFF\x00T\x00h\x00i\x00s\x00!"
};
-static git_off_t g_crlf_raw_len[CRLF_NUM_TEST_OBJECTS] = {
+static off64_t g_crlf_raw_len[CRLF_NUM_TEST_OBJECTS] = {
-1, -1, -1, -1, -1, 17, -1, -1, 12
};