Commit 6de3221d by Derrick Stolee

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>
parent 2c4eb83e
...@@ -200,7 +200,7 @@ int git_commit_graph_file_parse( ...@@ -200,7 +200,7 @@ int git_commit_graph_file_parse(
const unsigned char *chunk_hdr; const unsigned char *chunk_hdr;
struct git_commit_graph_chunk *last_chunk; struct git_commit_graph_chunk *last_chunk;
uint32_t i; uint32_t i;
off64_t last_chunk_offset, chunk_offset, trailer_offset; uint64_t last_chunk_offset, chunk_offset, trailer_offset;
size_t checksum_size; size_t checksum_size;
int error; int error;
struct git_commit_graph_chunk chunk_oid_fanout = {0}, chunk_oid_lookup = {0}, struct git_commit_graph_chunk chunk_oid_fanout = {0}, chunk_oid_lookup = {0},
...@@ -236,8 +236,8 @@ int git_commit_graph_file_parse( ...@@ -236,8 +236,8 @@ int git_commit_graph_file_parse(
chunk_hdr = data + sizeof(struct git_commit_graph_header); chunk_hdr = data + sizeof(struct git_commit_graph_header);
last_chunk = NULL; last_chunk = NULL;
for (i = 0; i < hdr->chunks; ++i, chunk_hdr += 12) { for (i = 0; i < hdr->chunks; ++i, chunk_hdr += 12) {
chunk_offset = ((off64_t)ntohl(*((uint32_t *)(chunk_hdr + 4)))) << 32 chunk_offset = ((uint64_t)ntohl(*((uint32_t *)(chunk_hdr + 4)))) << 32
| ((off64_t)ntohl(*((uint32_t *)(chunk_hdr + 8)))); | ((uint64_t)ntohl(*((uint32_t *)(chunk_hdr + 8))));
if (chunk_offset < last_chunk_offset) if (chunk_offset < last_chunk_offset)
return commit_graph_error("chunks are non-monotonic"); return commit_graph_error("chunks are non-monotonic");
if (chunk_offset >= trailer_offset) if (chunk_offset >= trailer_offset)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment