From patchwork Thu Nov 9 22:34:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13451836 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9443C38FB3 for ; Thu, 9 Nov 2023 22:34:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="iCg3XMj4" Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C1CD2D63 for ; Thu, 9 Nov 2023 14:34:14 -0800 (PST) Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-778a47bc09aso90110785a.3 for ; Thu, 09 Nov 2023 14:34:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1699569253; x=1700174053; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=k0GnV4Z+c6dZbNpid6RQ+HjufacG8wqK42c+ZwyHwlU=; b=iCg3XMj4IMFTqEIG1fP53hnZ4LNY7Uioom9dOtUDlg6YeoGXO1vDW1Zf2iQHlva51A GswDrUPWFpEYhswdmrfj7blVaOch0zcEUqc9gk58VE37NaY5MTlxcN4Wv7JJrpEIf5Cu mfipzHVGA4xorJYLxzslAUoKMyuYbAu4izBpBrmILXHwViPRefJ94lfsdETSi31aeJSO gh7KxzcBsmrlT4wEHyHBIQsGo20hDfY2iG0pHFIXnWk26eNqu01rd6+K04kcDpZkEhki dNey09ajRtGmz39OBlbhqtk6VRO9b9Dkwemthh0SUh1sdFjRe8jFKLDEk5HpJDLCdQRv HJ+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699569253; x=1700174053; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=k0GnV4Z+c6dZbNpid6RQ+HjufacG8wqK42c+ZwyHwlU=; b=pDlK8Hrdh6UOPWluZMd50ut79Ov/ECadLD0BB5Er6Dd2hEOAq7KrYyArByOMxDN1lw SL2SPwgkFl9fS14GSRBrcqHK73dTTKNjfsdY8KOha/TJjGtLN+9UYbEypJcrvmUnQdzK dVvNuXMJ8A1qWQvZ1/smZ32XMfbLdT56981nSy5FqAI2hujvUizxOZE3X6GPUtbZdruQ kv6Z3GntwLffcDZJPsNxIDh8xkVaAV9FVrNzk1QGrZ8kDD3+IWNbwWVN2tIR2cyaysOV EjukjBkfMfayoDTXdlpe8+rHxzVHOSY5seXYS6aKVbD8YtVdi14IGdqnQ2tyO3cW3BpP +Q3g== X-Gm-Message-State: AOJu0Yxkjuo5CQoTxTCOz5/eQ1y+XMweEcYJC3rtR3WlEeISX1Mtl+6d uD/wxz5BmU0IDebXSvuLuxytIhEV0oVkWdlbMa5SLw== X-Google-Smtp-Source: AGHT+IFknJ1TNULMkhYf2/dZXsP/r/ACSCik2uNjZYiO4YBvfdiRGGjYc99i5ZRkWbZzg0n7YjTRig== X-Received: by 2002:a05:620a:408b:b0:779:e90c:f203 with SMTP id f11-20020a05620a408b00b00779e90cf203mr6715192qko.9.1699569252890; Thu, 09 Nov 2023 14:34:12 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id z20-20020ae9c114000000b0076cb3690ae7sm248902qki.68.2023.11.09.14.34.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 14:34:12 -0800 (PST) Date: Thu, 9 Nov 2023 17:34:11 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH 1/7] chunk-format: introduce `pair_chunk_expect()` helper Message-ID: References: <20231109070310.GA2697602@coredump.intra.peff.net> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: In 570b8b8836 (chunk-format: note that pair_chunk() is unsafe, 2023-10-09), the pair_chunk() interface grew a required "size" pointer, so that the caller is forced to at least have a handle on the actual size of the given chunk. Many callers were converted to the new interface. A handful were instead converted from the unsafe version of pair_chunk() to read_chunk() so that they could check their expected size. This led to a lot of code like: static int graph_read_oid_lookup(const unsigned char *chunk_start, size_t chunk_size, void *data) { struct commit_graph *g = data; g->chunk_oid_lookup = chunk_start; if (chunk_size / g->hash_len != g->num_commits) return error(_("commit-graph OID lookup chunk is the wrong size")); return 0; } , leaving the caller to use read_chunk(), like so: read_chunk(cf, GRAPH_CHUNKID_OIDLOOKUP, graph_read_oid_lookup, graph); The callback to read_chunk() (in the above, `graph_read_oid_lookup()`) does nothing more than (a) assign a pointer to the location of the start of the chunk in the mmap'd file, and (b) assert that it has the correct size. For callers that know the expected size of their chunk(s) up-front (most often because they are made up of a known number of fixed-size records), we can simplify this by teaching the chunk-format API itself to validate the expected size for us. This is wrapped in a new function, called `pair_chunk_expect()` which takes a pair of "size_t"s (corresponding to the record size and count), instead of a "size_t *", and validates that the given chunk matches the expected size as given. This will allow us to reduce the number of lines of code it takes to perform these basic read_chunk() operations, by taking the above and replacing it with something like: if (pair_chunk_expect(cf, GRAPH_CHUNKID_OIDLOOKUP, &graph->chunk_oid_lookup, graph->hash_len, graph->num_commits)) error(_("commit-graph oid lookup chunk is wrong size")); We will perform those transformations in the following commits. Helped-by: Jeff King Signed-off-by: Taylor Blau --- chunk-format.c | 29 +++++++++++++++++++++++++++++ chunk-format.h | 13 ++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/chunk-format.c b/chunk-format.c index cdc7f39b70..be078dcca8 100644 --- a/chunk-format.c +++ b/chunk-format.c @@ -163,6 +163,10 @@ int read_table_of_contents(struct chunkfile *cf, struct pair_chunk_data { const unsigned char **p; size_t *size; + + /* for pair_chunk_expect() only */ + size_t record_size; + size_t record_nr; }; static int pair_chunk_fn(const unsigned char *chunk_start, @@ -175,6 +179,17 @@ static int pair_chunk_fn(const unsigned char *chunk_start, return 0; } +static int pair_chunk_expect_fn(const unsigned char *chunk_start, + size_t chunk_size, + void *data) +{ + struct pair_chunk_data *pcd = data; + if (chunk_size / pcd->record_size != pcd->record_nr) + return -1; + *pcd->p = chunk_start; + return 0; +} + int pair_chunk(struct chunkfile *cf, uint32_t chunk_id, const unsigned char **p, @@ -184,6 +199,20 @@ int pair_chunk(struct chunkfile *cf, return read_chunk(cf, chunk_id, pair_chunk_fn, &pcd); } +int pair_chunk_expect(struct chunkfile *cf, + uint32_t chunk_id, + const unsigned char **p, + size_t record_size, + size_t record_nr) +{ + struct pair_chunk_data pcd = { + .p = p, + .record_size = record_size, + .record_nr = record_nr, + }; + return read_chunk(cf, chunk_id, pair_chunk_expect_fn, &pcd); +} + int read_chunk(struct chunkfile *cf, uint32_t chunk_id, chunk_read_fn fn, diff --git a/chunk-format.h b/chunk-format.h index 14b76180ef..10806d7a9a 100644 --- a/chunk-format.h +++ b/chunk-format.h @@ -17,7 +17,8 @@ struct chunkfile; * * If reading a file, use a NULL 'struct hashfile *' and then call * read_table_of_contents(). Supply the memory-mapped data to the - * pair_chunk() or read_chunk() methods, as appropriate. + * pair_chunk(), pair_chunk_expect(), or read_chunk() methods, as + * appropriate. * * DO NOT MIX THESE MODES. Use different 'struct chunkfile' instances * for reading and writing. @@ -54,6 +55,16 @@ int pair_chunk(struct chunkfile *cf, const unsigned char **p, size_t *size); +/* + * Similar to 'pair_chunk', but used for callers who are reading a chunk + * with a known number of fixed-width records. + */ +int pair_chunk_expect(struct chunkfile *cf, + uint32_t chunk_id, + const unsigned char **p, + size_t record_size, + size_t record_nr); + typedef int (*chunk_read_fn)(const unsigned char *chunk_start, size_t chunk_size, void *data); /* From patchwork Thu Nov 9 22:34:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13451837 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1DB238F91 for ; Thu, 9 Nov 2023 22:34:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="O5K6igdR" Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 762C0420B for ; Thu, 9 Nov 2023 14:34:16 -0800 (PST) Received: by mail-qk1-x734.google.com with SMTP id af79cd13be357-778711ee748so91071685a.2 for ; Thu, 09 Nov 2023 14:34:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1699569255; x=1700174055; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=696+HX+GCK9IWWK4+KZKl3vji+WPm7c9povP4DkKz+A=; b=O5K6igdR3bPOwlWGh/+Zz/M3e5tj+mN7Qr85fSUBSz/F2J/ACt+m4NWjhZDCKHlI7t BZAw4XeQhMxKJNKmGHJbNp673ifYxkxi0SUQmzySMPyOdk0xndlw/UIC4EaazRZ3zvka 2QkD5NFmaE0ExFDBsQcq4gs1mYs+TqpKITMkTLbIO3k8Jkk4N4aR++ttRCh7dU8cNZnZ 3W3HcQP5p4DEuORDRBmMWhAnIAB3uSXPJYBgV5Df2bsS/7z/0rvi3ywn2tAahE72X5L2 7X4IrYPLM3FJqJNPii9OM+yqIFPD74t+zbpGDkoFiXpEaW269duNRs6zI8aFJjhZfixh X3aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699569255; x=1700174055; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=696+HX+GCK9IWWK4+KZKl3vji+WPm7c9povP4DkKz+A=; b=uN9VP/2AZpEy4uIOSal0o+R2Q1IaDkdidKOy9KxTyU/p2cWNA4TIYUjGNCTpsLJ93U r9DuRn9XWFReusWIWHtjNemNZKzUqQ1CNhcD+6XTuMSB4VTQp+CA8JyRL5v22nicT5f2 FGE1N4/9L8drJq8hmbSO8mtoEmpqVslxJpDuA7pQzLidCaNeD3gTyeqIR+gNtd2/IGJE 6vyiGf9IdqcTFnW5OWimsuHNA/UfItsfoc0YSa9f4Jjz9ucVrobRtGWnTcwWeosm9ylJ ZCx1MzbA4+INbHxDriIcCU8Er45UwiRDA2JVX1h5V6f7t4VmAN3+qpvHAMwhnG99c83C yCYA== X-Gm-Message-State: AOJu0YxC5P3tYyoxSz6h4wK/dN93fFIT85aioEBFmsUg5mfH6MM4p2N+ TNopmvRXRi3sFvEICI4s5hjKIo3NZaDTid8Jh/C3jQ== X-Google-Smtp-Source: AGHT+IF+VCTRJ4ZI2Kfovy5Zjq17bGbBMNaxj9+8quJctXg6y+t4vlChkvf5FWFWQpc+RNHcDW9yJA== X-Received: by 2002:a05:620a:28d5:b0:77b:c67a:4b59 with SMTP id l21-20020a05620a28d500b0077bc67a4b59mr402393qkp.3.1699569255355; Thu, 09 Nov 2023 14:34:15 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id rv9-20020a05620a688900b0077438383a07sm244469qkn.80.2023.11.09.14.34.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 14:34:15 -0800 (PST) Date: Thu, 9 Nov 2023 17:34:14 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH 2/7] commit-graph: read `OIDL` chunk with `pair_chunk_expect()` Message-ID: <5b3c0b99f8052733bb714122582ab229556c94ef.1699569246.git.me@ttaylorr.com> References: <20231109070310.GA2697602@coredump.intra.peff.net> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `OIDL` chunk can benefit from the new chunk-format API function described in the previous commit. Convert it to `pair_chunk_expect()` accordingly. While here, clean up some of the duplicate error messages to simplify the output when we are missing or have a corrupt OIDL chunk. Signed-off-by: Taylor Blau --- commit-graph.c | 16 ++++------------ t/t5318-commit-graph.sh | 3 +-- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index 93cf690565..6072c2a17f 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -299,16 +299,6 @@ static int graph_read_oid_fanout(const unsigned char *chunk_start, return 0; } -static int graph_read_oid_lookup(const unsigned char *chunk_start, - size_t chunk_size, void *data) -{ - struct commit_graph *g = data; - g->chunk_oid_lookup = chunk_start; - if (chunk_size / g->hash_len != g->num_commits) - return error(_("commit-graph OID lookup chunk is the wrong size")); - return 0; -} - static int graph_read_commit_data(const unsigned char *chunk_start, size_t chunk_size, void *data) { @@ -435,8 +425,10 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s, error(_("commit-graph required OID fanout chunk missing or corrupted")); goto free_and_return; } - if (read_chunk(cf, GRAPH_CHUNKID_OIDLOOKUP, graph_read_oid_lookup, graph)) { - error(_("commit-graph required OID lookup chunk missing or corrupted")); + if (pair_chunk_expect(cf, GRAPH_CHUNKID_OIDLOOKUP, + &graph->chunk_oid_lookup, graph->hash_len, + graph->num_commits)) { + error(_("commit-graph OID lookup chunk is the wrong size")); goto free_and_return; } if (read_chunk(cf, GRAPH_CHUNKID_DATA, graph_read_commit_data, graph)) { diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index b0d436a6f0..b3e8af018d 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -545,7 +545,7 @@ test_expect_success 'detect missing OID fanout chunk' ' test_expect_success 'detect missing OID lookup chunk' ' corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ID "\0" \ - "commit-graph required OID lookup chunk missing or corrupted" + "commit-graph OID lookup chunk is the wrong size" ' test_expect_success 'detect missing commit data chunk' ' @@ -851,7 +851,6 @@ test_expect_success 'reader notices fanout/lookup table mismatch' ' check_corrupt_chunk OIDF 1020 "FFFFFFFF" && cat >expect.err <<-\EOF && error: commit-graph OID lookup chunk is the wrong size - error: commit-graph required OID lookup chunk missing or corrupted EOF test_cmp expect.err err ' From patchwork Thu Nov 9 22:34:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13451838 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FA2B3984C for ; Thu, 9 Nov 2023 22:34:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="A/+xrTRJ" Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9D152D63 for ; Thu, 9 Nov 2023 14:34:20 -0800 (PST) Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-66d134a019cso8966126d6.3 for ; Thu, 09 Nov 2023 14:34:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1699569259; x=1700174059; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=WzCj/zAPXAisyinsnvEsPp7o5gd/chwi6G5f91Zfr/Y=; b=A/+xrTRJclqDIHyhosxgtyxXfGVE9bwyGgB8WxRYIyjtPrBf7K2Gs0L7+uRETMbQ06 zpZe3tiCqJwgtyKnyEiKkEGN1PIlI9PbWIjSv8OULF88TfGz5oxawk81kTPMN2McHq5f 0TmeIacFB+ZHL/WI6EKL16dK9LioiSUdi1T67nl7Yn520IPXsqkd2ePJTozc0dHn/tUk tuVkpiMD9xInyAb1HABNvvKL+IpbiZOiEYkc9Vc4SnF38FbgmRhiPW9IsqToYzl+lH+w lsxF2l6kcGUJ99tgWa8JN4x4+f8IX7KMApvqUCW9Y6gH/HEfkwE3b/QmDCjU/dFgqfaK LHyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699569259; x=1700174059; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WzCj/zAPXAisyinsnvEsPp7o5gd/chwi6G5f91Zfr/Y=; b=ffWoRiqRO1bFdluwJBeyWuIbjPM/pdL3LcfkhIbl6fAjEl4QCaZLFK6SOSsLGLtBdZ oxLEQMLM7ZhdKF3cTuUfY2d0gx4pRw3787XvIuithbaac5YPTcdSHZ1b7vHjpV/8cujH wRth70p3xkT7P7YUAQVasVQQjCLxNGP4sPmt3wg8/viiNP1+IuhA3ohrdf9KtvBgZwtQ g4Onh5ykv9Rx0PR6B4/5EVqicMKm8qIAkiXNeVL2heyZBG/THtQ7xS2Ri6Sk+vslJOCI rsM2fWsg4cKgJ9cPazGVcysLh3O3IgJKzGLLwAaLj30HP0ilev6RZDqw9tKjzqbRwoCF 4SMQ== X-Gm-Message-State: AOJu0Yx8AX0VsDTBwMRnpTw6mczyLAfKPOeVU8b75r3o66EaIf66Z6WF PYu+AeL5mCQ277URxxwG5kSSeUsNtThMo1DJUeF4zQ== X-Google-Smtp-Source: AGHT+IG9Aoha1W45eVytoeO7a3uaXj3nsFKQoCWPLdYvbL14fuB1YIw3oHGgJmEx4CByah1uGKB+dA== X-Received: by 2002:a05:6214:c41:b0:658:71e1:5490 with SMTP id r1-20020a0562140c4100b0065871e15490mr6160294qvj.21.1699569259730; Thu, 09 Nov 2023 14:34:19 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id pl14-20020ad4468e000000b006714f8b5512sm2435676qvb.6.2023.11.09.14.34.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 14:34:19 -0800 (PST) Date: Thu, 9 Nov 2023 17:34:18 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH 3/7] commit-graph: read `CDAT` chunk with `pair_chunk_expect()` Message-ID: <400a2ee7f464df0b659ee9ac2f5e112d65e4ff9a.1699569246.git.me@ttaylorr.com> References: <20231109070310.GA2697602@coredump.intra.peff.net> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `CDAT` chunk can benefit from the new chunk-format API function described in the previous commit. Convert it to `pair_chunk_expect()` accordingly. Signed-off-by: Taylor Blau --- commit-graph.c | 15 +++------------ t/t5318-commit-graph.sh | 3 +-- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index 6072c2a17f..67ab0f2448 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -299,16 +299,6 @@ static int graph_read_oid_fanout(const unsigned char *chunk_start, return 0; } -static int graph_read_commit_data(const unsigned char *chunk_start, - size_t chunk_size, void *data) -{ - struct commit_graph *g = data; - if (chunk_size / GRAPH_DATA_WIDTH != g->num_commits) - return error(_("commit-graph commit data chunk is wrong size")); - g->chunk_commit_data = chunk_start; - return 0; -} - static int graph_read_generation_data(const unsigned char *chunk_start, size_t chunk_size, void *data) { @@ -431,8 +421,9 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s, error(_("commit-graph OID lookup chunk is the wrong size")); goto free_and_return; } - if (read_chunk(cf, GRAPH_CHUNKID_DATA, graph_read_commit_data, graph)) { - error(_("commit-graph required commit data chunk missing or corrupted")); + if (pair_chunk_expect(cf, GRAPH_CHUNKID_DATA, &graph->chunk_commit_data, + GRAPH_DATA_WIDTH, graph->num_commits)) { + error(_("commit-graph commit data chunk is wrong size")); goto free_and_return; } diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index b3e8af018d..fd5165bd07 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -550,7 +550,7 @@ test_expect_success 'detect missing OID lookup chunk' ' test_expect_success 'detect missing commit data chunk' ' corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATA_ID "\0" \ - "commit-graph required commit data chunk missing or corrupted" + "commit-graph commit data chunk is wrong size" ' test_expect_success 'detect incorrect fanout' ' @@ -875,7 +875,6 @@ test_expect_success 'reader notices too-small commit data chunk' ' check_corrupt_chunk CDAT clear 00000000 && cat >expect.err <<-\EOF && error: commit-graph commit data chunk is wrong size - error: commit-graph required commit data chunk missing or corrupted EOF test_cmp expect.err err ' From patchwork Thu Nov 9 22:34:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13451839 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 203F039856 for ; Thu, 9 Nov 2023 22:34:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="xov8Lq+2" Received: from mail-oo1-xc2a.google.com (mail-oo1-xc2a.google.com [IPv6:2607:f8b0:4864:20::c2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6FF42D63 for ; Thu, 9 Nov 2023 14:34:23 -0800 (PST) Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-586f68b78ddso764888eaf.2 for ; Thu, 09 Nov 2023 14:34:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1699569262; x=1700174062; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=E6uvJ8CYZIzc8Ud08TRsM4z79zgntDfUAlcG+b4Q9AU=; b=xov8Lq+2xFIRCcoYoFDDPcYVHRwAMi0Vkz+m2RWYWAuiNWPY3EBrEStRr2oBZ7Aagr ejYFdoTmAaYwZvfkiCZWCYx1tgOgvZEih0tI4m8fOOFJKY7OC5E/cx/R4S5yXa8VVTUW j1uWDfvjXr2zFE/V11RBnZ10+Yb4WRWmeUpd49KLQF1r366BFkl/QstmtOOzDSX8G75s ro1i30D+axMBMZYfa7oilOLzVwi+b0Hs0x0NxxrKSC9qYo4jPXA/DQ4/lFUK6QIJX7Q1 MX8By6kl4DYBysrNVWPRoHAtFlzLrdEXkeAm2OkOJeAZK0kxqtSiLuaCiwb15Y48vgiQ quXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699569262; x=1700174062; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=E6uvJ8CYZIzc8Ud08TRsM4z79zgntDfUAlcG+b4Q9AU=; b=Wl9ex1W+qwXanAkQBgVh/YsYXTVTgtdopES8ivcm9AJaf6NgrcWCpdgxtRbMpP2Ktj 41P1/eBkyeFZTS5tBneBsFLwHsF/y+C3nJyAO8y7ZkJUV2CiQHM2oOGPO0FPMJmHYrHo JYQDUchD0Ff9rSVLH+saQuDLFFu+jilxuS8smG7FnAUyCduJlfhQM2LdeSQMxrUdb9SM w25z7+OdmyKvuj53wcghzOEKZWOvGqdMTWPuTk8NTmkR23IrkUJG7XZGGQUhqBU8cCh9 ikAc8axh/hVsX7L7sIs7R/jT5MOLzR4/rp97AtWUYxgXAf23U11TlOVfb+3EvOHiG/FS 9tDA== X-Gm-Message-State: AOJu0YzSe6HqPKisZPgCC0CSPXZnwV3KR9tEvMzuP6CW0WEwV8fE95A5 Zf4hZvH4JytRhk9EhICfsXEQRhuIuszCP/7Eq4HpYQ== X-Google-Smtp-Source: AGHT+IEaF+S66tzKTAurUALee7fDMqEwdXi4x/17Xf+LfMOPWMOUxSdT1vKfNqYRgdIf7fLtPapFPg== X-Received: by 2002:a05:6358:9392:b0:169:49f7:cb1c with SMTP id h18-20020a056358939200b0016949f7cb1cmr7514048rwb.8.1699569262584; Thu, 09 Nov 2023 14:34:22 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id k20-20020ac84794000000b004179e79069asm2293857qtq.21.2023.11.09.14.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 14:34:22 -0800 (PST) Date: Thu, 9 Nov 2023 17:34:21 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH 4/7] commit-graph: read `GDAT` chunk with `pair_chunk_expect()` Message-ID: References: <20231109070310.GA2697602@coredump.intra.peff.net> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `GDAT` chunk can benefit from the new chunk-format API function described in the previous commit. Convert it to `pair_chunk_expect()` accordingly. Signed-off-by: Taylor Blau --- commit-graph.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index 67ab0f2448..3b456d199f 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -299,16 +299,6 @@ static int graph_read_oid_fanout(const unsigned char *chunk_start, return 0; } -static int graph_read_generation_data(const unsigned char *chunk_start, - size_t chunk_size, void *data) -{ - struct commit_graph *g = data; - if (chunk_size / sizeof(uint32_t) != g->num_commits) - return error(_("commit-graph generations chunk is wrong size")); - g->chunk_generation_data = chunk_start; - return 0; -} - static int graph_read_bloom_index(const unsigned char *chunk_start, size_t chunk_size, void *data) { @@ -433,8 +423,11 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s, &graph->chunk_base_graphs_size); if (s->commit_graph_generation_version >= 2) { - read_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA, - graph_read_generation_data, graph); + if (pair_chunk_expect(cf, GRAPH_CHUNKID_GENERATION_DATA, + &graph->chunk_generation_data, + sizeof(uint32_t), + graph->num_commits)) + error(_("commit-graph generations chunk is wrong size")); pair_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA_OVERFLOW, &graph->chunk_generation_data_overflow, &graph->chunk_generation_data_overflow_size); From patchwork Thu Nov 9 22:34:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13451840 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF2B439863 for ; Thu, 9 Nov 2023 22:34:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="YF/fpzTU" Received: from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FC0F2D63 for ; Thu, 9 Nov 2023 14:34:26 -0800 (PST) Received: by mail-oo1-xc34.google.com with SMTP id 006d021491bc7-5842a94feb2so773595eaf.0 for ; Thu, 09 Nov 2023 14:34:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1699569265; x=1700174065; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=3FDbHaI/JadI9HKCO6pbZxSp5CFQwHyNxGX4QDfRTwg=; b=YF/fpzTUHeTRccj810FM+SAAEKU7QC0KloioIqTfaZYdluTyEJ2AMdfAb7Z9iT5LKh 46DGC+yo+JT2mtmWahOBeA1VY1jCzxsUd1FgoNwZG2+XUOWpeb+dhTa4+jRB8yh9rFQx /odqizM//28Yr2djeqXel53tkSYbEcesFIbmyUbkDpUOy8ZkQLTs8U6E5tm1VaiWB0kT iKISogcgY9PhEgiB5tccu5+4K1sZLwW5zsRuH6C0fnOwQ2hAMgIUaAwtT9x1rmh78X07 NSbogUeERrYhgBHOq5tivyQ7K3sUfpv5n8rpqY1c6sPppr+ygilmgTAr/Ug77ixt4AcL v5Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699569265; x=1700174065; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3FDbHaI/JadI9HKCO6pbZxSp5CFQwHyNxGX4QDfRTwg=; b=wzZVU5uLIFXs46mwUO7ignjwZ5g8Q5bF4RbjEopx8QGItDn52HQ2uc0ERnf+EwMt74 53PSrJg64TZ/yXbmAVQ9/LUIjGAzqDVii1iqxMqatt7BlD1QM1e58jfv9mFY1I1znkvw Cz+vFQEH/jL6LfzXjkWxD+h/cEVLamGGibdDFUnQqapxTXwqnrr90yM+Co/WFTeOpGzC C/TXaVbraxKR/dQmyzk38FxGUjg44ZQ979B4GFKLKZLQzOGS30SdmOF1rjh5Cbq/JOEU TOUYCrT9muQFygUtrKga2LaQijp3PVY5tDWQ+xp2dg0Os4fOqVN02XWBfWgESQfhx3yc VAvA== X-Gm-Message-State: AOJu0YxWjNM3HYq3a2IIfNT4Qhq4vThJkZ0JkhD68nkrOcqlFvm9WDgx hiW9ZcD112eQle4/wNl+O5P7ezduhQT3YCp5+r3b8Q== X-Google-Smtp-Source: AGHT+IGtoXtithsqJ1ROjpc8/upBKvYnzDpBZyWEFL/W+UH4FwY49w7EW+SqMiq5u3Nibfdyx8oMgg== X-Received: by 2002:a05:6358:5e0c:b0:169:9788:8741 with SMTP id q12-20020a0563585e0c00b0016997888741mr5423392rwn.27.1699569265209; Thu, 09 Nov 2023 14:34:25 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id c16-20020ac853d0000000b0041eef6cacf4sm2298482qtq.81.2023.11.09.14.34.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 14:34:25 -0800 (PST) Date: Thu, 9 Nov 2023 17:34:24 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH 5/7] commit-graph: read `BIDX` chunk with `pair_chunk_expect()` Message-ID: <1f556f5b02d69bed688cc290d22ed8b7e646c4a7.1699569246.git.me@ttaylorr.com> References: <20231109070310.GA2697602@coredump.intra.peff.net> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `BIDX` chunk can benefit from the new chunk-format API function described in the previous commit. Convert it to `pair_chunk_expect()` accordingly. Signed-off-by: Taylor Blau --- commit-graph.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index 3b456d199f..76d220508b 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -299,18 +299,6 @@ static int graph_read_oid_fanout(const unsigned char *chunk_start, return 0; } -static int graph_read_bloom_index(const unsigned char *chunk_start, - size_t chunk_size, void *data) -{ - struct commit_graph *g = data; - if (chunk_size / 4 != g->num_commits) { - warning(_("commit-graph changed-path index chunk is too small")); - return -1; - } - g->chunk_bloom_indexes = chunk_start; - return 0; -} - static int graph_read_bloom_data(const unsigned char *chunk_start, size_t chunk_size, void *data) { @@ -437,8 +425,11 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s, } if (s->commit_graph_read_changed_paths) { - read_chunk(cf, GRAPH_CHUNKID_BLOOMINDEXES, - graph_read_bloom_index, graph); + int res = pair_chunk_expect(cf, GRAPH_CHUNKID_BLOOMINDEXES, + &graph->chunk_bloom_indexes, + sizeof(uint32_t), graph->num_commits); + if (res && res != CHUNK_NOT_FOUND) + warning(_("commit-graph changed-path index chunk is too small")); read_chunk(cf, GRAPH_CHUNKID_BLOOMDATA, graph_read_bloom_data, graph); } From patchwork Thu Nov 9 22:34:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13451841 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6376038FAD for ; Thu, 9 Nov 2023 22:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="0+Yqbr7P" Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6DF82D63 for ; Thu, 9 Nov 2023 14:34:28 -0800 (PST) Received: by mail-qk1-x72d.google.com with SMTP id af79cd13be357-77891f362cfso118926585a.1 for ; Thu, 09 Nov 2023 14:34:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1699569268; x=1700174068; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=fE/0gP3h92H6q2grDmi4MIhWQHAzT6ox8nv+VdRFXJw=; b=0+Yqbr7P0ygayRitb9CIvW8nNV7jJIQO497KYNdiVj7HMRw4a9U+WdxPwH2h3PyqfJ qY0t19o15PPVFZHFsnq284xBAbZpXaVEvtczSjGwk4YGyTEw2FGwj1Y8Ju7SXMuwvp+Q wvpBy1RZ7DnDOQzaEz8hOzx+XBliVuTe8Gngh1D6w/bgbu+3b9wBGXtntjWf1APK3PQ+ F1Gjbd49s7/NsAajiBGImKIL9nfka6DLKg6zh8DxDN4p1brIZebDZoUArmbcpkld4eFX QRn3KL5YXjtw2sN/vYl+Pk06y70ydBcfjGdMmEsOFEPIHe6ccSeye4kEj8J8rdgse/RD o23A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699569268; x=1700174068; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=fE/0gP3h92H6q2grDmi4MIhWQHAzT6ox8nv+VdRFXJw=; b=U3F5ydb4lcXrk4Jl97wnunA6CzaRvefmfiFw4pGm38K3c+RnSISjlzj5ED8mKzuoev LF9SaJU3TXm5M+hbkjnxqEGwfZi6h6G+QbsEGjBvLoImE78bDqe5Snlt98yJZ3+dgcti p4wi+Qc4Bwcu7XZPCpfb8kFfrSInJCub9CCzFX0zZdmESHpY3OqW60Yy7yYrmxNWc7Oo tXI1CPKuV613QEXxuAGgEPldFphjwq/BihcmKXQpPw/IWYccdQWmM0T0lUxujIrsLSoB cr0aZJ1VD/xITQfjcIXk+yi62Z3CNJ9aiPgj3iATKh+++ao5npO2sjJB9GNgRRSi2fva 9QVg== X-Gm-Message-State: AOJu0YwEbHNNU7Bo1Q5cQGMiOzIgCtgVs+BKW4DrzNHs6gRhKgW7Dk1P Zl0/vnZrIpe88CzZ5GtRdLo+mRv9vRD3EwiqgciTPQ== X-Google-Smtp-Source: AGHT+IHrRx1pk1jtXi5si++8wY8aPBCfLmzI+IFQdSj2r3WL7NK4CgT2hr2jnEiUtPwf4rt0L77NfQ== X-Received: by 2002:a05:620a:2408:b0:778:8ebc:129f with SMTP id d8-20020a05620a240800b007788ebc129fmr1051744qkn.8.1699569267792; Thu, 09 Nov 2023 14:34:27 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id y17-20020ac87091000000b00419c40a0d70sm2332035qto.54.2023.11.09.14.34.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 14:34:27 -0800 (PST) Date: Thu, 9 Nov 2023 17:34:26 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH 6/7] midx: read `OIDL` chunk with `pair_chunk_expect()` Message-ID: References: <20231109070310.GA2697602@coredump.intra.peff.net> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `OIDL` chunk can benefit from the new chunk-format API function described in the previous commit. Convert it to `pair_chunk_expect()` accordingly. Signed-off-by: Taylor Blau --- midx.c | 16 ++-------------- t/t5319-multi-pack-index.sh | 1 - 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/midx.c b/midx.c index 1d14661dad..66f34ed1a3 100644 --- a/midx.c +++ b/midx.c @@ -86,19 +86,6 @@ static int midx_read_oid_fanout(const unsigned char *chunk_start, return 0; } -static int midx_read_oid_lookup(const unsigned char *chunk_start, - size_t chunk_size, void *data) -{ - struct multi_pack_index *m = data; - m->chunk_oid_lookup = chunk_start; - - if (chunk_size != st_mult(m->hash_len, m->num_objects)) { - error(_("multi-pack-index OID lookup chunk is the wrong size")); - return 1; - } - return 0; -} - static int midx_read_object_offsets(const unsigned char *chunk_start, size_t chunk_size, void *data) { @@ -186,7 +173,8 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local die(_("multi-pack-index required pack-name chunk missing or corrupted")); if (read_chunk(cf, MIDX_CHUNKID_OIDFANOUT, midx_read_oid_fanout, m)) die(_("multi-pack-index required OID fanout chunk missing or corrupted")); - if (read_chunk(cf, MIDX_CHUNKID_OIDLOOKUP, midx_read_oid_lookup, m)) + if (pair_chunk_expect(cf, MIDX_CHUNKID_OIDLOOKUP, &m->chunk_oid_lookup, + m->hash_len, m->num_objects)) die(_("multi-pack-index required OID lookup chunk missing or corrupted")); if (read_chunk(cf, MIDX_CHUNKID_OBJECTOFFSETS, midx_read_object_offsets, m)) die(_("multi-pack-index required object offsets chunk missing or corrupted")); diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index 313496c0cf..2d68616c59 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -1077,7 +1077,6 @@ test_expect_success 'reader notices too-small oid lookup chunk' ' corrupt_chunk OIDL clear 00000000 && test_must_fail git log 2>err && cat >expect <<-\EOF && - error: multi-pack-index OID lookup chunk is the wrong size fatal: multi-pack-index required OID lookup chunk missing or corrupted EOF test_cmp expect err From patchwork Thu Nov 9 22:34:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13451842 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECE833984C for ; Thu, 9 Nov 2023 22:34:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="MTzuC7dk" Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E01E2D63 for ; Thu, 9 Nov 2023 14:34:31 -0800 (PST) Received: by mail-qt1-x82b.google.com with SMTP id d75a77b69052e-41eae4f0ee6so9250941cf.3 for ; Thu, 09 Nov 2023 14:34:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1699569270; x=1700174070; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=zle5ZNhB+UwAR7G7/cow/My6dhR+1Xu8cKgtyP7ptW4=; b=MTzuC7dkvtbTA9eGaXb4T+aCFcaFSP/8E6o43cGkemqxfNtPc8gLIOPTnNogDEFRkP cE//LFkREoqUhX71iXJUURKJq6LnkMbYXjzGzsqmuPymgWLY0OqvXLN6vbtp2pTGAxtM xaDpLRY/I1wbl+xgR2SxbJUlvMSS9M+tg0lF3CrXJFoyXendaBjHp8wGH+nUIpUk6BsF 2O2nSLJdkaERGTUNSqLUHOd3i/KLvtBJSp9I+6UkvdeWPf6tgJwNj2v5JeAnfVYlaEhe JDwXgykBykf+inJQ0rm2vakq31my9IglzmDIOJQOC6J0khi9OmJYJkb6vvp2gBPZZbTj 90zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699569270; x=1700174070; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zle5ZNhB+UwAR7G7/cow/My6dhR+1Xu8cKgtyP7ptW4=; b=gZhu5RcJK4VI/pWD7vde/Dvt3r6560H2vxCGm7zaDKeLVqexgqMaWtFnbiFf8r9oEv gPnM09RvDG0b/H/ibMIo4Kmg0hcGsU3mcaFVg2vELIqO5ZA+35G1+jW+Q8urhfrbvBDO b/bhroyS+4uoglOaOGg6iRy5uxBXtRAk4/5Kcl3y/b/ROTZCA71rRHMk0T8j6aLSZhbW Ch6gAwgXuGbRW0qiY4sHqvPRAYiyQ73pJRkHDCuStC0AK9WvnoH7wwCLlHv5/AEszTkR FIZpOmXM5e3NkBw5a3lbegzs7h5k2xEIJg+uXefkIm3C6UwqFjYh4TcrSgpUOLxNIYka 53DA== X-Gm-Message-State: AOJu0Yxk7jxM0h4KgHxFhh3r9nVjlZUsp2g9YeFYv4DKFe004xuz+0M0 WonDbfc+3gjPf9W1P0uDo520c8ELwafqHLmvhn/VvQ== X-Google-Smtp-Source: AGHT+IFyDEi0CmJbs7tveExSV+NzfKFMUBxmndUx5ldH7YeYN7S4kf/cuSX5Kvlc/GRevMXlH6SyaQ== X-Received: by 2002:a05:622a:1883:b0:41c:bf98:dab1 with SMTP id v3-20020a05622a188300b0041cbf98dab1mr5461376qtc.13.1699569270366; Thu, 09 Nov 2023 14:34:30 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id b19-20020ac844d3000000b004180fb5c6adsm2303852qto.25.2023.11.09.14.34.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 14:34:30 -0800 (PST) Date: Thu, 9 Nov 2023 17:34:29 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH 7/7] midx: read `OOFF` chunk with `pair_chunk_expect()` Message-ID: <44bd344727622b86a00424f37dbaa0c35d85189a.1699569246.git.me@ttaylorr.com> References: <20231109070310.GA2697602@coredump.intra.peff.net> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `OOFF` chunk can benefit from the new chunk-format API function described in the previous commit. Convert it to `pair_chunk_expect()` accordingly. Signed-off-by: Taylor Blau --- midx.c | 17 +++-------------- t/t5319-multi-pack-index.sh | 1 - 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/midx.c b/midx.c index 66f34ed1a3..ca41748b74 100644 --- a/midx.c +++ b/midx.c @@ -86,19 +86,6 @@ static int midx_read_oid_fanout(const unsigned char *chunk_start, return 0; } -static int midx_read_object_offsets(const unsigned char *chunk_start, - size_t chunk_size, void *data) -{ - struct multi_pack_index *m = data; - m->chunk_object_offsets = chunk_start; - - if (chunk_size != st_mult(m->num_objects, MIDX_CHUNK_OFFSET_WIDTH)) { - error(_("multi-pack-index object offset chunk is the wrong size")); - return 1; - } - return 0; -} - struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local) { struct multi_pack_index *m = NULL; @@ -176,7 +163,9 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local if (pair_chunk_expect(cf, MIDX_CHUNKID_OIDLOOKUP, &m->chunk_oid_lookup, m->hash_len, m->num_objects)) die(_("multi-pack-index required OID lookup chunk missing or corrupted")); - if (read_chunk(cf, MIDX_CHUNKID_OBJECTOFFSETS, midx_read_object_offsets, m)) + if (pair_chunk_expect(cf, MIDX_CHUNKID_OBJECTOFFSETS, + &m->chunk_object_offsets, MIDX_CHUNK_OFFSET_WIDTH, + m->num_objects)) die(_("multi-pack-index required object offsets chunk missing or corrupted")); pair_chunk(cf, MIDX_CHUNKID_LARGEOFFSETS, &m->chunk_large_offsets, diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index 2d68616c59..f1f6764efe 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -1111,7 +1111,6 @@ test_expect_success 'reader notices too-small object offset chunk' ' corrupt_chunk OOFF clear 00000000 && test_must_fail git log 2>err && cat >expect <<-\EOF && - error: multi-pack-index object offset chunk is the wrong size fatal: multi-pack-index required object offsets chunk missing or corrupted EOF test_cmp expect err