Skip to content

Commit 366115e

Browse files
committed
Review feedback
1 parent fff209c commit 366115e

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

src/midx.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -643,12 +643,7 @@ static int midx_write(
643643
int error = 0;
644644
size_t i;
645645
struct git_pack_file *p;
646-
struct git_midx_header hdr = {
647-
.signature = htonl(MIDX_SIGNATURE),
648-
.version = MIDX_VERSION,
649-
.object_id_version = MIDX_OBJECT_ID_VERSION,
650-
.base_midx_files = 0,
651-
};
646+
struct git_midx_header hdr = {0};
652647
uint32_t oid_fanout_count;
653648
uint32_t object_large_offsets_count;
654649
uint32_t oid_fanout[256];
@@ -662,11 +657,16 @@ static int midx_write(
662657
object_entry_array_t object_entries_array = GIT_ARRAY_INIT;
663658
git_vector object_entries = GIT_VECTOR_INIT;
664659
git_hash_ctx ctx;
665-
struct midx_write_hash_context hash_cb_data = {
666-
.write_cb = write_cb,
667-
.cb_data = cb_data,
668-
.ctx = &ctx,
669-
};
660+
struct midx_write_hash_context hash_cb_data = {0};
661+
662+
hdr.signature = htonl(MIDX_SIGNATURE);
663+
hdr.version = MIDX_VERSION;
664+
hdr.object_id_version = MIDX_OBJECT_ID_VERSION;
665+
hdr.base_midx_files = 0;
666+
667+
hash_cb_data.write_cb = write_cb;
668+
hash_cb_data.cb_data = cb_data;
669+
hash_cb_data.ctx = &ctx;
670670

671671
error = git_hash_ctx_init(&ctx);
672672
if (error < 0)
@@ -677,12 +677,12 @@ static int midx_write(
677677
git_vector_sort(&w->packs);
678678
git_vector_foreach (&w->packs, i, p) {
679679
git_buf relative_index = GIT_BUF_INIT;
680-
struct object_entry_cb_state state = {
681-
.pack_index = (uint32_t)i,
682-
.object_entries_array = &object_entries_array,
683-
};
680+
struct object_entry_cb_state state = {0};
684681
size_t path_len;
685682

683+
state.pack_index = (uint32_t)i;
684+
state.object_entries_array = &object_entries_array;
685+
686686
error = git_buf_sets(&relative_index, p->pack_name);
687687
if (error < 0)
688688
goto cleanup;
@@ -694,6 +694,8 @@ static int midx_write(
694694
path_len = git_buf_len(&relative_index);
695695
if (path_len <= strlen(".pack") || git__suffixcmp(git_buf_cstr(&relative_index), ".pack") != 0) {
696696
git_buf_dispose(&relative_index);
697+
git_error_set(GIT_ERROR_INVALID, "invalid packfile name: '%s'", p->pack_name);
698+
error = -1;
697699
goto cleanup;
698700
}
699701
path_len -= strlen(".pack");

src/pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,7 @@ int git_pack_foreach_entry_offset(
13961396

13971397
index += 4 * 256;
13981398

1399+
/* all offsets should have been validated by pack_index_check_locked */
13991400
if (p->index_version > 1) {
14001401
const unsigned char *offsets = index + 24 * p->num_objects;
14011402
const unsigned char *large_offset_ptr;
@@ -1406,7 +1407,7 @@ int git_pack_foreach_entry_offset(
14061407
if (current_offset & 0x80000000) {
14071408
large_offset_ptr = large_offsets + (current_offset & 0x7fffffff) * 8;
14081409
if (large_offset_ptr >= large_offsets_end) {
1409-
error = -1;
1410+
error = packfile_error("invalid large offset");
14101411
goto cleanup;
14111412
}
14121413
current_offset = (((off64_t)ntohl(*((uint32_t *)(large_offset_ptr + 0)))) << 32) |

src/pack.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* Function type for callbacks from git_pack_foreach_entry_offset.
2525
*/
26-
typedef int GIT_CALLBACK(git_pack_foreach_entry_offset_cb)(
26+
typedef int git_pack_foreach_entry_offset_cb(
2727
const git_oid *id,
2828
off64_t offset,
2929
void *payload);
@@ -185,8 +185,11 @@ int git_pack_foreach_entry(
185185
git_odb_foreach_cb cb,
186186
void *data);
187187
/**
188-
* Similar to git_pack_foreach_entry, but it also provides the offset of the
189-
* object within the packfile. It also does not sort the objects in any order.
188+
* Similar to git_pack_foreach_entry, but:
189+
* - It also provides the offset of the object within the
190+
* packfile.
191+
* - It does not sort the objects in any order.
192+
* - It retains the lock while invoking the callback.
190193
*/
191194
int git_pack_foreach_entry_offset(
192195
struct git_pack_file *p,

0 commit comments

Comments
 (0)