Skip to content

Commit 92da944

Browse files
jeffhostetlerdscho
authored andcommitted
gvfs-helper: ignore .idx files in prefetch multi-part responses
The GVFS cache server can return multiple pairs of (.pack, .idx) files. If both are provided, `gvfs-helper` assumes that they are valid without any validation. This might cause problems if the .pack file is corrupt inside the data stream. (This might happen if the cache server sends extra unexpected STDERR data or if the .pack file is corrupt on the cache server's disk.) All of the .pack file verification logic is already contained within `git index-pack`, so let's ignore the .idx from the data stream and force compute it. This defeats the purpose of some of the data cacheing on the cache server, but safety is more important. Signed-off-by: Jeff Hostetler <[email protected]>
1 parent dd843bb commit 92da944

File tree

2 files changed

+24
-38
lines changed

2 files changed

+24
-38
lines changed

gvfs-helper.c

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,7 +2124,6 @@ static void extract_packfile_from_multipack(
21242124
{
21252125
struct ph ph;
21262126
struct tempfile *tempfile_pack = NULL;
2127-
struct tempfile *tempfile_idx = NULL;
21282127
int result = -1;
21292128
int b_no_idx_in_multipack;
21302129
struct object_id packfile_checksum;
@@ -2158,16 +2157,14 @@ static void extract_packfile_from_multipack(
21582157
b_no_idx_in_multipack = (ph.idx_len == maximum_unsigned_value_of_type(uint64_t) ||
21592158
ph.idx_len == 0);
21602159

2161-
if (b_no_idx_in_multipack) {
2162-
my_create_tempfile(status, 0, "pack", &tempfile_pack, NULL, NULL);
2163-
if (!tempfile_pack)
2164-
goto done;
2165-
} else {
2166-
/* create a pair of tempfiles with the same basename */
2167-
my_create_tempfile(status, 0, "pack", &tempfile_pack, "idx", &tempfile_idx);
2168-
if (!tempfile_pack || !tempfile_idx)
2169-
goto done;
2170-
}
2160+
/*
2161+
* We are going to harden `gvfs-helper` here and ignore the .idx file
2162+
* if it is provided and always compute it locally so that we get the
2163+
* added verification that `git index-pack` provides.
2164+
*/
2165+
my_create_tempfile(status, 0, "pack", &tempfile_pack, NULL, NULL);
2166+
if (!tempfile_pack)
2167+
goto done;
21712168

21722169
/*
21732170
* Copy the current packfile from the open stream and capture
@@ -2194,38 +2191,31 @@ static void extract_packfile_from_multipack(
21942191

21952192
oid_to_hex_r(hex_checksum, &packfile_checksum);
21962193

2197-
if (b_no_idx_in_multipack) {
2198-
/*
2199-
* The server did not send the corresponding .idx, so
2200-
* we have to compute it ourselves.
2201-
*/
2202-
strbuf_addbuf(&temp_path_idx, &temp_path_pack);
2203-
strbuf_strip_suffix(&temp_path_idx, ".pack");
2204-
strbuf_addstr(&temp_path_idx, ".idx");
2194+
/*
2195+
* Always compute the .idx file from the .pack file.
2196+
*/
2197+
strbuf_addbuf(&temp_path_idx, &temp_path_pack);
2198+
strbuf_strip_suffix(&temp_path_idx, ".pack");
2199+
strbuf_addstr(&temp_path_idx, ".idx");
22052200

2206-
my_run_index_pack(params, status,
2207-
&temp_path_pack, &temp_path_idx,
2208-
NULL);
2209-
if (status->ec != GH__ERROR_CODE__OK)
2210-
goto done;
2201+
my_run_index_pack(params, status,
2202+
&temp_path_pack, &temp_path_idx,
2203+
NULL);
2204+
if (status->ec != GH__ERROR_CODE__OK)
2205+
goto done;
22112206

2212-
} else {
2207+
if (!b_no_idx_in_multipack) {
22132208
/*
22142209
* Server sent the .idx immediately after the .pack in the
2215-
* data stream. I'm tempted to verify it, but that defeats
2216-
* the purpose of having it cached...
2210+
* data stream. Skip over it.
22172211
*/
2218-
if (my_copy_fd_len(fd_multipack, get_tempfile_fd(tempfile_idx),
2219-
ph.idx_len) < 0) {
2212+
if (lseek(fd_multipack, ph.idx_len, SEEK_CUR) < 0) {
22202213
strbuf_addf(&status->error_message,
2221-
"could not extract index[%d] in multipack",
2214+
"could not skip index[%d] in multipack",
22222215
k);
22232216
status->ec = GH__ERROR_CODE__COULD_NOT_INSTALL_PREFETCH;
22242217
goto done;
22252218
}
2226-
2227-
strbuf_addstr(&temp_path_idx, get_tempfile_path(tempfile_idx));
2228-
close_tempfile_gently(tempfile_idx);
22292219
}
22302220

22312221
strbuf_addf(&buf_timestamp, "%u", (unsigned int)ph.timestamp);
@@ -2240,7 +2230,6 @@ static void extract_packfile_from_multipack(
22402230

22412231
done:
22422232
delete_tempfile(&tempfile_pack);
2243-
delete_tempfile(&tempfile_idx);
22442233
strbuf_release(&temp_path_pack);
22452234
strbuf_release(&temp_path_idx);
22462235
strbuf_release(&final_path_pack);

t/t5799-gvfs-helper.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,14 +1367,11 @@ test_expect_success 'prefetch corrupt pack without idx' '
13671367

13681368
# Send corrupt PACK files with IDX files. Since the cache server
13691369
# sends both, `gvfs-helper` might fail to verify both of them.
1370-
test_expect_failure 'prefetch corrupt pack with corrupt idx' '
1370+
test_expect_success 'prefetch corrupt pack with corrupt idx' '
13711371
test_when_finished "per_test_cleanup" &&
13721372
start_gvfs_protocol_server_with_mayhem \
13731373
bad_prefetch_pack_sha &&
13741374
1375-
# TODO This is a false-positive since `gvfs-helper`
1376-
# TODO does not verify either of them when a pair
1377-
# TODO is sent.
13781375
test_must_fail \
13791376
git -C "$REPO_T1" gvfs-helper \
13801377
--cache-server=disable \

0 commit comments

Comments
 (0)