Skip to content

Commit 6f09672

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 38f4be7 commit 6f09672

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
@@ -2128,7 +2128,6 @@ static void extract_packfile_from_multipack(
21282128
{
21292129
struct ph ph;
21302130
struct tempfile *tempfile_pack = NULL;
2131-
struct tempfile *tempfile_idx = NULL;
21322131
int result = -1;
21332132
int b_no_idx_in_multipack;
21342133
struct object_id packfile_checksum;
@@ -2162,16 +2161,14 @@ static void extract_packfile_from_multipack(
21622161
b_no_idx_in_multipack = (ph.idx_len == maximum_unsigned_value_of_type(uint64_t) ||
21632162
ph.idx_len == 0);
21642163

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

21762173
/*
21772174
* Copy the current packfile from the open stream and capture
@@ -2198,38 +2195,31 @@ static void extract_packfile_from_multipack(
21982195

21992196
oid_to_hex_r(hex_checksum, &packfile_checksum);
22002197

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

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

2216-
} else {
2211+
if (!b_no_idx_in_multipack) {
22172212
/*
22182213
* Server sent the .idx immediately after the .pack in the
2219-
* data stream. I'm tempted to verify it, but that defeats
2220-
* the purpose of having it cached...
2214+
* data stream. Skip over it.
22212215
*/
2222-
if (my_copy_fd_len(fd_multipack, get_tempfile_fd(tempfile_idx),
2223-
ph.idx_len) < 0) {
2216+
if (lseek(fd_multipack, ph.idx_len, SEEK_CUR) < 0) {
22242217
strbuf_addf(&status->error_message,
2225-
"could not extract index[%d] in multipack",
2218+
"could not skip index[%d] in multipack",
22262219
k);
22272220
status->ec = GH__ERROR_CODE__COULD_NOT_INSTALL_PREFETCH;
22282221
goto done;
22292222
}
2230-
2231-
strbuf_addstr(&temp_path_idx, get_tempfile_path(tempfile_idx));
2232-
close_tempfile_gently(tempfile_idx);
22332223
}
22342224

22352225
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
@@ -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)