Skip to content

Commit 80fdeca

Browse files
jeffhostetlervdye
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 aa66f2b commit 80fdeca

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
@@ -2132,7 +2132,6 @@ static void extract_packfile_from_multipack(
21322132
{
21332133
struct ph ph;
21342134
struct tempfile *tempfile_pack = NULL;
2135-
struct tempfile *tempfile_idx = NULL;
21362135
int result = -1;
21372136
int b_no_idx_in_multipack;
21382137
struct object_id packfile_checksum;
@@ -2166,16 +2165,14 @@ static void extract_packfile_from_multipack(
21662165
b_no_idx_in_multipack = (ph.idx_len == maximum_unsigned_value_of_type(uint64_t) ||
21672166
ph.idx_len == 0);
21682167

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

21802177
/*
21812178
* Copy the current packfile from the open stream and capture
@@ -2202,38 +2199,31 @@ static void extract_packfile_from_multipack(
22022199

22032200
oid_to_hex_r(hex_checksum, &packfile_checksum);
22042201

2205-
if (b_no_idx_in_multipack) {
2206-
/*
2207-
* The server did not send the corresponding .idx, so
2208-
* we have to compute it ourselves.
2209-
*/
2210-
strbuf_addbuf(&temp_path_idx, &temp_path_pack);
2211-
strbuf_strip_suffix(&temp_path_idx, ".pack");
2212-
strbuf_addstr(&temp_path_idx, ".idx");
2202+
/*
2203+
* Always compute the .idx file from the .pack file.
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");
22132208

2214-
my_run_index_pack(params, status,
2215-
&temp_path_pack, &temp_path_idx,
2216-
NULL);
2217-
if (status->ec != GH__ERROR_CODE__OK)
2218-
goto done;
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;
22192214

2220-
} else {
2215+
if (!b_no_idx_in_multipack) {
22212216
/*
22222217
* Server sent the .idx immediately after the .pack in the
2223-
* data stream. I'm tempted to verify it, but that defeats
2224-
* the purpose of having it cached...
2218+
* data stream. Skip over it.
22252219
*/
2226-
if (my_copy_fd_len(fd_multipack, get_tempfile_fd(tempfile_idx),
2227-
ph.idx_len) < 0) {
2220+
if (lseek(fd_multipack, ph.idx_len, SEEK_CUR) < 0) {
22282221
strbuf_addf(&status->error_message,
2229-
"could not extract index[%d] in multipack",
2222+
"could not skip index[%d] in multipack",
22302223
k);
22312224
status->ec = GH__ERROR_CODE__COULD_NOT_INSTALL_PREFETCH;
22322225
goto done;
22332226
}
2234-
2235-
strbuf_addstr(&temp_path_idx, get_tempfile_path(tempfile_idx));
2236-
close_tempfile_gently(tempfile_idx);
22372227
}
22382228

22392229
strbuf_addf(&buf_timestamp, "%u", (unsigned int)ph.timestamp);
@@ -2248,7 +2238,6 @@ static void extract_packfile_from_multipack(
22482238

22492239
done:
22502240
delete_tempfile(&tempfile_pack);
2251-
delete_tempfile(&tempfile_idx);
22522241
strbuf_release(&temp_path_pack);
22532242
strbuf_release(&temp_path_idx);
22542243
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)