Skip to content

Commit 85cff8d

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 17ce06c commit 85cff8d

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
@@ -2127,7 +2127,6 @@ static void extract_packfile_from_multipack(
21272127
{
21282128
struct ph ph;
21292129
struct tempfile *tempfile_pack = NULL;
2130-
struct tempfile *tempfile_idx = NULL;
21312130
int result = -1;
21322131
int b_no_idx_in_multipack;
21332132
struct object_id packfile_checksum;
@@ -2161,16 +2160,14 @@ static void extract_packfile_from_multipack(
21612160
b_no_idx_in_multipack = (ph.idx_len == maximum_unsigned_value_of_type(uint64_t) ||
21622161
ph.idx_len == 0);
21632162

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

21752172
/*
21762173
* Copy the current packfile from the open stream and capture
@@ -2197,38 +2194,31 @@ static void extract_packfile_from_multipack(
21972194

21982195
oid_to_hex_r(hex_checksum, &packfile_checksum);
21992196

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

2209-
my_run_index_pack(params, status,
2210-
&temp_path_pack, &temp_path_idx,
2211-
NULL);
2212-
if (status->ec != GH__ERROR_CODE__OK)
2213-
goto done;
2204+
my_run_index_pack(params, status,
2205+
&temp_path_pack, &temp_path_idx,
2206+
NULL);
2207+
if (status->ec != GH__ERROR_CODE__OK)
2208+
goto done;
22142209

2215-
} else {
2210+
if (!b_no_idx_in_multipack) {
22162211
/*
22172212
* Server sent the .idx immediately after the .pack in the
2218-
* data stream. I'm tempted to verify it, but that defeats
2219-
* the purpose of having it cached...
2213+
* data stream. Skip over it.
22202214
*/
2221-
if (my_copy_fd_len(fd_multipack, get_tempfile_fd(tempfile_idx),
2222-
ph.idx_len) < 0) {
2215+
if (lseek(fd_multipack, ph.idx_len, SEEK_CUR) < 0) {
22232216
strbuf_addf(&status->error_message,
2224-
"could not extract index[%d] in multipack",
2217+
"could not skip index[%d] in multipack",
22252218
k);
22262219
status->ec = GH__ERROR_CODE__COULD_NOT_INSTALL_PREFETCH;
22272220
goto done;
22282221
}
2229-
2230-
strbuf_addstr(&temp_path_idx, get_tempfile_path(tempfile_idx));
2231-
close_tempfile_gently(tempfile_idx);
22322222
}
22332223

22342224
strbuf_addf(&buf_timestamp, "%u", (unsigned int)ph.timestamp);
@@ -2244,7 +2234,6 @@ static void extract_packfile_from_multipack(
22442234

22452235
done:
22462236
delete_tempfile(&tempfile_pack);
2247-
delete_tempfile(&tempfile_idx);
22482237
strbuf_release(&temp_path_pack);
22492238
strbuf_release(&temp_path_idx);
22502239
strbuf_release(&final_path_pack);

t/t5799-gvfs-helper.sh

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

13781378
# Send corrupt PACK files with IDX files. Since the cache server
13791379
# sends both, `gvfs-helper` might fail to verify both of them.
1380-
test_expect_failure 'prefetch corrupt pack with corrupt idx' '
1380+
test_expect_success 'prefetch corrupt pack with corrupt idx' '
13811381
test_when_finished "per_test_cleanup" &&
13821382
start_gvfs_protocol_server_with_mayhem \
13831383
bad_prefetch_pack_sha &&
13841384
1385-
# TODO This is a false-positive since `gvfs-helper`
1386-
# TODO does not verify either of them when a pair
1387-
# TODO is sent.
13881385
test_must_fail \
13891386
git -C "$REPO_T1" gvfs-helper \
13901387
--cache-server=disable \

0 commit comments

Comments
 (0)