Skip to content

Commit 6de3221

Browse files
committed
commit_graph: use uint64_t for arithmetic
This should resolve some issues with UBSan builds by using unsigned 64-bit integers for all arithmetic until we finally convert to an offset or size value. Signed-off-by: Derrick Stolee <derrickstolee@github.com>
1 parent 2c4eb83 commit 6de3221

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/libgit2/commit_graph.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ int git_commit_graph_file_parse(
200200
const unsigned char *chunk_hdr;
201201
struct git_commit_graph_chunk *last_chunk;
202202
uint32_t i;
203-
off64_t last_chunk_offset, chunk_offset, trailer_offset;
203+
uint64_t last_chunk_offset, chunk_offset, trailer_offset;
204204
size_t checksum_size;
205205
int error;
206206
struct git_commit_graph_chunk chunk_oid_fanout = {0}, chunk_oid_lookup = {0},
@@ -236,8 +236,8 @@ int git_commit_graph_file_parse(
236236
chunk_hdr = data + sizeof(struct git_commit_graph_header);
237237
last_chunk = NULL;
238238
for (i = 0; i < hdr->chunks; ++i, chunk_hdr += 12) {
239-
chunk_offset = ((off64_t)ntohl(*((uint32_t *)(chunk_hdr + 4)))) << 32
240-
| ((off64_t)ntohl(*((uint32_t *)(chunk_hdr + 8))));
239+
chunk_offset = ((uint64_t)ntohl(*((uint32_t *)(chunk_hdr + 4)))) << 32
240+
| ((uint64_t)ntohl(*((uint32_t *)(chunk_hdr + 8))));
241241
if (chunk_offset < last_chunk_offset)
242242
return commit_graph_error("chunks are non-monotonic");
243243
if (chunk_offset >= trailer_offset)

0 commit comments

Comments
 (0)