From patchwork Mon Mar 20 20:02:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13181806 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A14D3C6FD1D for ; Mon, 20 Mar 2023 20:03:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230264AbjCTUDE (ORCPT ); Mon, 20 Mar 2023 16:03:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229882AbjCTUDA (ORCPT ); Mon, 20 Mar 2023 16:03:00 -0400 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CF0527D6D for ; Mon, 20 Mar 2023 13:02:42 -0700 (PDT) Received: by mail-il1-x12c.google.com with SMTP id i19so7075983ila.10 for ; Mon, 20 Mar 2023 13:02:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; t=1679342562; 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=qNweSWarDDL6D6PfGWXryB9GRQymDMh0xU8ckrfKFhI=; b=Z19uI5yyXYnPt9dsN5JAHXzTxKHInT6GvuRzQOGPcZl458AnczbNHilpnVBesHsCSA 3okqKxOkaKDUSNIgyaIw7A/bt2atw4AXZ2c/WsJ97oPr/xfHv/LcTzaDznSN0WQcxT9i wNijA+w5ENou82VbOKLfJTvk3oYSB4GP2ZmXZQdJ6oa6G2potnXN7UtHiYP5wF75+vHK dAK9q7POQpdH9PJ2mu2V9eKxkeQ1bC8pp6STbGfluZT9oRGa2HhQ6ALvY4vaZ6gMVsAE tJJSP+4rNkyf+BxOEEtnMxetaiV2TSoZ7lC8wWPvORUVmWKrKearzcwiXphXXbXHn8v+ 4E3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679342562; 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=qNweSWarDDL6D6PfGWXryB9GRQymDMh0xU8ckrfKFhI=; b=oYgsLzIwaLgXoAQhtoKBW8wkulq3imBpqSUp8kcPaWeqMINuUwFtZHT3ZpN09j0v0L c0aaWAzL9ATJHVadR0YH5moTp0gGwHY6JP1p+9iCQsq1rkDiS4T1KJ/G8PIBAj1LFPDc UNTPe4hd+yM8dTpUJ1btg3ab4aZ1DQWaa2ql1FnKZ74quwUPHm1WHKtkP8yfftvTYOri lFqOJdhzbXJ5y3cSMC2modv6JkFeoyRi82sxkiaXse3++rBbxotGIgQ7Jsz4HP1dCmi+ BWnnLvjzLSp1ZIXf41eAac/XJ8a0YS6rRpGbnNdICDW9B/PPvZDFanhvaf2XYdZCAqTe hFHg== X-Gm-Message-State: AO0yUKW7VWqh6DpyJ1PYs+MNyhiFmdKDla428UUEqjgIcKCsGt0pTF7T 5+OSsDJAnl54WQdsuyHBFi+AVTqTlC+Wxwu29m9NNA== X-Google-Smtp-Source: AK7set8naRTVj7MeAp/moOavIi7lMJkVzet8LdmR8aj0vP/EUjC/UrJ9gIVCW72AoKXM9Nv8TaE7Ww== X-Received: by 2002:a92:7412:0:b0:314:17d4:e9f6 with SMTP id p18-20020a927412000000b0031417d4e9f6mr5856412ilc.6.1679342561816; Mon, 20 Mar 2023 13:02:41 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id i11-20020a92540b000000b00313b08feec7sm2967900ilb.42.2023.03.20.13.02.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 13:02:41 -0700 (PDT) Date: Mon, 20 Mar 2023 16:02:40 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Abhradeep Chakraborty , Jeff King Subject: [PATCH 1/6] pack-bitmap.c: hide bitmap internals in `read_u8()` Message-ID: <8c70c94a3f5f0463041dbaaa542fd69bd159428b.1679342296.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The `read_u8()` helper function internal to pack-bitmap.c was defined in b5007211b6 (pack-bitmap: do not use gcc packed attribute, 2014-11-27). Prior to b5007211b6, callers within pack-bitmap.c would read an individual unsigned integer by doing something like: struct bitmap_disk_entry *e; e = (struct bitmap_disk_entry *)(index->map + index->map_pos); index->map_pos += sizeof(*e); ...which relied on the fact that the `bitmap_disk_entry` struct was defined with `__attribute((packed))`, which b5007211b6 sought to get rid of since the `__attribute__` flag is a noop on some compilers (which makes the above code rely on the absence of padding to be correct). So b5007211b6 got rid of the above convention and replaced it by reading individual fields of that structure with a `read_u8()` helper that reads from the region of memory pointed to by `->map`, and updates the `->map_pos` pointer accordingly. But this forces callers to be intimately aware of `bitmap_git->map` and `bitmap_git->map_pos`. Instead, teach `read_u8()` to take a `struct bitmap_index *` directly, and avoid having callers deal with the internals themselves. Signed-off-by: Taylor Blau --- pack-bitmap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pack-bitmap.c b/pack-bitmap.c index ca7c81b5c9..d8ba252ba1 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -251,9 +251,9 @@ static inline uint32_t read_be32(const unsigned char *buffer, size_t *pos) return result; } -static inline uint8_t read_u8(const unsigned char *buffer, size_t *pos) +static inline uint8_t read_u8(struct bitmap_index *bitmap_git) { - return buffer[(*pos)++]; + return bitmap_git->map[bitmap_git->map_pos++]; } #define MAX_XOR_OFFSET 160 @@ -283,8 +283,8 @@ static int load_bitmap_entries_v1(struct bitmap_index *index) return error(_("corrupt ewah bitmap: truncated header for entry %d"), i); commit_idx_pos = read_be32(index->map, &index->map_pos); - xor_offset = read_u8(index->map, &index->map_pos); - flags = read_u8(index->map, &index->map_pos); + xor_offset = read_u8(index); + flags = read_u8(index); if (nth_bitmap_object_oid(index, &oid, commit_idx_pos) < 0) return error(_("corrupt ewah bitmap: commit index %u out of range"), @@ -780,7 +780,7 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_ } bitmap_git->map_pos += sizeof(uint32_t) + sizeof(uint8_t); - xor_flags = read_u8(bitmap_git->map, &bitmap_git->map_pos); + xor_flags = read_u8(bitmap_git); bitmap = read_bitmap_1(bitmap_git); if (!bitmap) @@ -821,7 +821,7 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_ * ewah bitmap. */ bitmap_git->map_pos += sizeof(uint32_t) + sizeof(uint8_t); - flags = read_u8(bitmap_git->map, &bitmap_git->map_pos); + flags = read_u8(bitmap_git); bitmap = read_bitmap_1(bitmap_git); if (!bitmap) From patchwork Mon Mar 20 20:02:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13181807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33F04C6FD1C for ; Mon, 20 Mar 2023 20:03:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230206AbjCTUDN (ORCPT ); Mon, 20 Mar 2023 16:03:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230149AbjCTUDH (ORCPT ); Mon, 20 Mar 2023 16:03:07 -0400 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69AB04ED0 for ; Mon, 20 Mar 2023 13:02:46 -0700 (PDT) Received: by mail-il1-x134.google.com with SMTP id r4so7086107ilt.8 for ; Mon, 20 Mar 2023 13:02:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; t=1679342565; 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=3M0RUwC8NqbI54+W2PYI1fm4kPL+s41dBwUnD+TCbZU=; b=ncdBLtbwIZLJhbQGuSszUG+tK9QV9ZMyHy6FnMujlhRljhlIL8jOeWY999OyeED5oC e26+WhSHl7T17Q1qhaBzMcQrQANXJh10G3cM0aD4do63GPR9d8Te20B5Tk6rqhHVLYXp 2QGSDBGBcWW23QNEU85qJtPo3RDjVDZ5P8+AlcTGFgMcAZvWOcsLKQjOiuA8QrlFbTiD zcmDXl5a1WEcyGVNdvJj8kfCxqLM1ugHHScSzu5bP2fQWiyxtYte7D6LObCcybxy9mkD j5nZq3KqmpABU1ZJrsLasoUl9Aye4kFYroZuWJazNPJW+DfeK4HQ1rvW3D2wqLkiQ0tc OpJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679342565; 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=3M0RUwC8NqbI54+W2PYI1fm4kPL+s41dBwUnD+TCbZU=; b=wgxtcakMz4+fMOBbWsi9f3zn9AdZKnGU0SF7taDrvdoICvJxZNSrnkd2oRulUe7DPo 5oJomXv1xt3GoSagD5P7kex+1qz86BF+xogLB7XU5qj8gS/nSZAbrZe611dQKAYL7pBB TjAoBDfyDyPlGYQDuCle3icz8/02Zci3K5yLcC+xu45PmRNO9vKz+GBS24nPNl+X3Gs8 56rDe6ad6TpbdCPKQghFPNYCBxIkvOyZd9BWERgo2EABzFFKJbnjif7VRA01Tgr+EVJv OhdiWXuVd6+NO7s//piF6r3tfjzO7pUDqeYvrvhaNmUZoq2EIQYojriUKSwmDlgVQ0HQ sQKg== X-Gm-Message-State: AO0yUKUql+elESldXpjy3JyBQ3GB0Nnr3Tf4FAl3DWOYpQ386hBlvS7E d7nBnoyxZGaV5CfZC+I7lK1K5QUugn9G3Xdi9CA3JQ== X-Google-Smtp-Source: AK7set9n8rZ2B6Qx+KIvUdRtqW6tdwEm+fd9IcR8AY8vJ1lmEp+zASuQqsro/xb8BM9mh/uiBJOftA== X-Received: by 2002:a92:dcca:0:b0:314:20e6:133c with SMTP id b10-20020a92dcca000000b0031420e6133cmr509858ilr.3.1679342564755; Mon, 20 Mar 2023 13:02:44 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id r14-20020a92760e000000b00304ad1e7d21sm3040101ilc.28.2023.03.20.13.02.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 13:02:44 -0700 (PDT) Date: Mon, 20 Mar 2023 16:02:43 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Abhradeep Chakraborty , Jeff King Subject: [PATCH 2/6] pack-bitmap.c: hide bitmap internals in `read_be32()` Message-ID: <4914c5b72c3aab9f59589daf8daff5e2271c52fb.1679342296.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a similar fashion as the previous commit, update `read_be32()` to take a `struct bitmap_index *` instead of copies of and pointers to variables within that structure. Signed-off-by: Taylor Blau --- pack-bitmap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pack-bitmap.c b/pack-bitmap.c index d8ba252ba1..794aaf5b02 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -244,10 +244,10 @@ static struct stored_bitmap *store_bitmap(struct bitmap_index *index, return stored; } -static inline uint32_t read_be32(const unsigned char *buffer, size_t *pos) +static inline uint32_t read_be32(struct bitmap_index *bitmap_git) { - uint32_t result = get_be32(buffer + *pos); - (*pos) += sizeof(result); + uint32_t result = get_be32(bitmap_git->map + bitmap_git->map_pos); + bitmap_git->map_pos += sizeof(result); return result; } @@ -282,7 +282,7 @@ static int load_bitmap_entries_v1(struct bitmap_index *index) if (index->map_size - index->map_pos < 6) return error(_("corrupt ewah bitmap: truncated header for entry %d"), i); - commit_idx_pos = read_be32(index->map, &index->map_pos); + commit_idx_pos = read_be32(index); xor_offset = read_u8(index); flags = read_u8(index); From patchwork Mon Mar 20 20:02:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13181808 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CEEFC6FD1C for ; Mon, 20 Mar 2023 20:03:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229565AbjCTUDQ (ORCPT ); Mon, 20 Mar 2023 16:03:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229882AbjCTUDJ (ORCPT ); Mon, 20 Mar 2023 16:03:09 -0400 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81A2D15572 for ; Mon, 20 Mar 2023 13:02:48 -0700 (PDT) Received: by mail-io1-xd34.google.com with SMTP id k17so5990576iob.1 for ; Mon, 20 Mar 2023 13:02:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; t=1679342567; 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=xnsltWRRFw2DqseSJzOximSHpgRGcQT4Zd+BJx5DlCE=; b=JWIpwQ4rCRwf4NYXUWoQBGeWseF3ZDRdMnx/+hAKy7lMb0+P2J8yF2OiN0l4Knct2p Y6ltvUgNTbSDSE8RjtDnj+f3FGVSaiA1wrD/YXQQ9TtgrFHmoAin4S18qcCZJwxHLpJC iwxcihIZR8kOFylZYCSWXZb6KSjZlls18lanaHQNWCyWEDiT9UuOvwwjq8b0gy8mlBzw rT+TbiBZyf/ClZrPiASBlUgxf9JBnd2QvTrEwgDw7/hgcugRSMGqCjwsv+lbq06/UQZR lJwCTsL847useECquK3WmJ/3wwxJRYocWqH+l58glDlNGQHBaJC0rgk2VJbng3zildXT rxZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679342567; 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=xnsltWRRFw2DqseSJzOximSHpgRGcQT4Zd+BJx5DlCE=; b=Nwq0EEov7ZksBfqs0pw+biIK0ixG/BqChrxOfunf2dMv2n0lS13JfOTcKdGS7AfNtP QXYefzeCLu9EJ/qvgbeHpJXl7tcL8YN5aSOiYO4/aWoWIWHh8DVmrzAVaPmUdZwN5PfX M8xmBX51jjjNfRXN/jFIrfmBxcUAnUU5hG1iBA8+dS7KttKAbLGxceCwzf6qqFaJeBFZ wYN4e7bED66QXBp/KLbvbNPbI0RUDiv3X1iRNp4jpN7D1/evhoibVN0jSAT+HOcC2boE M8LN6xBIe7/1dus/7r+VEVJ2RH5W8KX2rAHJAPX6x6GThk4P4kBn33K6iE1ilhOXL7kK zNJA== X-Gm-Message-State: AO0yUKVIXauKGOL6/imoRZWxQXHWAj53cCqSw17RxG6WK5iBTNNnAf4d YqaiS41Psbp7Ec2+1LoaLYT/+H5djI8CtFR2Pj4F8A== X-Google-Smtp-Source: AK7set+mmwBviT8rS17UMeBdckp8kb0RNtTgKYtYWAahwO0fFkWSUS7tt3qBh2rifp7hJNwZmSKB5w== X-Received: by 2002:a5d:9342:0:b0:6df:fa5a:fa05 with SMTP id i2-20020a5d9342000000b006dffa5afa05mr151689ioo.0.1679342567551; Mon, 20 Mar 2023 13:02:47 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id z5-20020a027a45000000b0040535426261sm3472830jad.37.2023.03.20.13.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 13:02:47 -0700 (PDT) Date: Mon, 20 Mar 2023 16:02:46 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Abhradeep Chakraborty , Jeff King Subject: [PATCH 3/6] pack-bitmap.c: drop unnecessary 'inline's Message-ID: <2e3e3a7145a5851fcf5c485b38d14344c9b824d7.1679342296.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Both `read_be32()` and `read_u8()` are defined as inline dating back to b5007211b6 (pack-bitmap: do not use gcc packed attribute, 2014-11-27), though that commit does not hint at why the functions were defined with that attribute. However (at least with GCC 12.2.0, at the time of writing), the resulting pack-bitmap.o contains the same instructions with or without the inline attribute applied to these functions: $ make O=3 pack-bitmap.o && mv pack-bitmap.o{,.before} [ apply this patch ] $ make O=3 pack-bitmap.o && mv pack-bitmap.o{,.after} $ objdump -d pack-bitmap.o.before >before $ objdump -d pack-bitmap.o.after >after $ diff -u pack-bitmap.o.{before,after} --- before 2023-03-15 18:54:17.021580095 -0400 +++ after 2023-03-15 18:54:21.853552218 -0400 @@ -1,5 +1,5 @@ -pack-bitmap.o.before: file format elf64-x86-64 +pack-bitmap.o.after: file format elf64-x86-64 Disassembly of section .text: So defining these functions as inline is at best a noop, and at worst confuses the reader into thinking that there is some trickier reason that they are defined as inline when there isn't. Since this pair of functions does not need to be inlined, let's drop that attribute from both `read_u8()` and `read_be32()`. Signed-off-by: Taylor Blau --- pack-bitmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pack-bitmap.c b/pack-bitmap.c index 794aaf5b02..1d12f90ff9 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -244,14 +244,14 @@ static struct stored_bitmap *store_bitmap(struct bitmap_index *index, return stored; } -static inline uint32_t read_be32(struct bitmap_index *bitmap_git) +static uint32_t read_be32(struct bitmap_index *bitmap_git) { uint32_t result = get_be32(bitmap_git->map + bitmap_git->map_pos); bitmap_git->map_pos += sizeof(result); return result; } -static inline uint8_t read_u8(struct bitmap_index *bitmap_git) +static uint8_t read_u8(struct bitmap_index *bitmap_git) { return bitmap_git->map[bitmap_git->map_pos++]; } From patchwork Mon Mar 20 20:02:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13181809 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75107C6FD1D for ; Mon, 20 Mar 2023 20:03:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231139AbjCTUDZ (ORCPT ); Mon, 20 Mar 2023 16:03:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230027AbjCTUDQ (ORCPT ); Mon, 20 Mar 2023 16:03:16 -0400 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 779EE2056B for ; Mon, 20 Mar 2023 13:02:51 -0700 (PDT) Received: by mail-il1-x135.google.com with SMTP id h11so7074702ild.11 for ; Mon, 20 Mar 2023 13:02:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; t=1679342570; 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=HTWs/PUt06EEBTz1ChEU6aISoFhv60JKfI/pIpQ5kl0=; b=BPVyBxz3AKwsDqbrcMNaUbZLVfoUTxWGzAaC8pKYzD2+8DT5a/RKDGXAK6QnuSQABA Vzp7AwWRz52irXpJM6jwguCKNJ0L4L+X46XK0HqbFSolmnDYOJDgt9n18YDHTtzR0YDu jmwLRXIJ4GxeK5eMNBHdOykX6E8yL1w+MqHHHUxhnO5qtdUKYvl3Nq8bNiWT8Zr3AUaN mVgzHAtW62Z40OqLu/zvCbor/0yj3TFh9RXg1edyiCz6MdwVCWWGV0bxFpwozWAMBWkT oZ6xKur9NVQbvY9+FdAVXBJZicE5qh/asXQOThuc1aoyvZsntZ0bpkaY6pGgEVYhW1UT J6eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679342570; 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=HTWs/PUt06EEBTz1ChEU6aISoFhv60JKfI/pIpQ5kl0=; b=FCHtfvCm+tKCq7N3VoBKgyjL/x5tV6WTq1YLo2GCmCiPgj0tx1PQN5i6vPPKKHuXyS u7g4FZ8WLJ75C4fhpZ+kPMKpp27cN7XG9M6x9qWufrMcrOxKml+d0QNAnYoS2S21B2b8 H/U1DPlcfeu+hKedRJfGyXsnFkS739Aw2xEr0maRuJwxE58Tl4fDzsPunEKaejtGRV6m e9oo1QESZQNIq9+gyJmiGJfFywKwQzMYFtfw3yi7uwYp4Ybn5TzNyuYqaB4QHZnI2voj mqeDDKqcsQsW1lIO75/ZV+vsb3R8GMlkVpv3SB86Ws08/HQCnCKvW7RrM+9gY1U1/hMH pU5A== X-Gm-Message-State: AO0yUKXhEcsLMEPwSp7ZnvNMXFG6q79QJBJcvht5nn5Ts2OyYluG83+w WsyBMaX6K1DLAgrMWD4XROdKuh5DCS1pLxfaejv1/Q== X-Google-Smtp-Source: AK7set97PsWHhOZGaN0zcWID5koasmkLgNgqi8kkgwhMaWnFjAcwxB+W5pjSsW+PFzJeCOXOarxL7Q== X-Received: by 2002:a92:d249:0:b0:315:9891:85d7 with SMTP id v9-20020a92d249000000b00315989185d7mr504026ilg.16.1679342570378; Mon, 20 Mar 2023 13:02:50 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id w20-20020a056e0213f400b00314201bcbdfsm3021683ilj.3.2023.03.20.13.02.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 13:02:50 -0700 (PDT) Date: Mon, 20 Mar 2023 16:02:49 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Abhradeep Chakraborty , Jeff King Subject: [PATCH 4/6] pack-bitmap.c: factor out manual `map_pos` manipulation Message-ID: <0decf13869df6216914044a560d94968126836f4.1679342296.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The pack-bitmap internals use a combination of a `map` and `map_pos` variable to keep a pointer to a memory mapped region of the `.bitmap` file, as well as the position within that file, respectively. Reads within the memory mapped region are meant to mimic file reads, where each read adjusts the offset of the file descriptor accordingly. This functionality is implemented by adjusting the `map_pos` variable after each read. Factor out a function similar to seek() which adjusts the `map_pos` variable for us. Since the bitmap code only needs to adjust relative to the beginning of the file as well as the current position, we do not need to support any "whence" values outside of SEEK_SET and SEEK_CUR. Extracting out this operation into a separate function allows us to add some additional safety checks, such as ensuring that adding to `map_pos` does not overflow `size_t`, and that the resulting `map_pos` value is in bounds of the mapped region. The subsequent commit will rewrite all manual manipulation of the `map_pos` variable in terms of the new `bitmap_index_seek()`. Signed-off-by: Taylor Blau --- pack-bitmap.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pack-bitmap.c b/pack-bitmap.c index 1d12f90ff9..fabcf01c14 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -134,6 +134,28 @@ static struct ewah_bitmap *lookup_stored_bitmap(struct stored_bitmap *st) return composed; } +static size_t bitmap_index_seek(struct bitmap_index *bitmap_git, size_t offset, + int whence) +{ + switch (whence) { + case SEEK_SET: + bitmap_git->map_pos = offset; + break; + case SEEK_CUR: + bitmap_git->map_pos = st_add(bitmap_git->map_pos, offset); + break; + default: + BUG("unhandled seek whence: %d", whence); + } + + if (bitmap_git->map_pos >= bitmap_git->map_size) + BUG("bitmap position exceeds size (%"PRIuMAX" >= %"PRIuMAX")", + (uintmax_t)bitmap_git->map_pos, + (uintmax_t)bitmap_git->map_size); + + return bitmap_git->map_pos; +} + /* * Read a bitmap from the current read position on the mmaped * index, and increase the read position accordingly From patchwork Mon Mar 20 20:02:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13181810 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7443C6FD1C for ; Mon, 20 Mar 2023 20:03:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230395AbjCTUD1 (ORCPT ); Mon, 20 Mar 2023 16:03:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230321AbjCTUDS (ORCPT ); Mon, 20 Mar 2023 16:03:18 -0400 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29C472D44 for ; Mon, 20 Mar 2023 13:02:55 -0700 (PDT) Received: by mail-il1-x131.google.com with SMTP id bp11so7095658ilb.3 for ; Mon, 20 Mar 2023 13:02:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; t=1679342573; 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=GeXZQEB1xM+JoBV53w/xzzVWBFhPhNSGC4ynfnsdxL4=; b=v8sEH9WHDh8HOZoX4uk6dHCI77jc7Dp7+++IaK6S5WmznBRlva2B/442ViaaT8UuPM Ssiy0Co0pRpw04eyBLM8XVJq+jDFHrxSJClUjWC4zpSu0fO/pFktkPv2lDpRaJJ+5So3 wF2ZlRqyFamAW20K6/56HaH4zzRiXhuAtpP8WGhFFgYMAFjKUuLIxIb6/AWcMKBG6B9D ay6yc7Cq+wnvBXWIeKSz5c7egKhvUVWh6acoRHShmznNzlgfV0sTVWMfHw/tUD6Zvu3r C52TCwRceW59LPTl8Vs80UhFKAUcciQTkpPT9mRwC9TVrWH0sSFxHHxgn6onrggApjf/ 4koQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679342573; 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=GeXZQEB1xM+JoBV53w/xzzVWBFhPhNSGC4ynfnsdxL4=; b=1ix9S3XG22ib6mVspr+qo5MQ7leB91M0o2aH0PVBR7sYqVSiKWbp6kjaM6puzDdsn9 ZPC4xVphVI1l2iALI9pmfUdG6Dwj5NePUo/6/lbC8kS0npn/tYaW0ZxyGIypkGJL2X4L HbPXXYrPkXua5okLumTfaeVpZR0cIH69pizP4m7NZxDB1u8C6/gg3V2kEp9l+X2HyR1D gd12em5vXLQTTRZR0y6/UVaCwTpxKl1u/tyx2svN6VD1yDtslOogWhychpZf65B+zwXt b6zjzKsMdmOR+tL+nqaYPgk+VNgkcQh7MWkDnwR5kJ+Nf5mUkM3yyvsLLVugP+xzLhmL lUUw== X-Gm-Message-State: AO0yUKUHbtUQ6NTXaCINXiO13rrFeuGTdD52GkZ+HrgmVrA4tBtnRKcH 8JNWq+z9N5Gv+EMnTVOHNSJZC7Ai7YhUQD/0Yi1msg== X-Google-Smtp-Source: AK7set9inoMfYhuBmCDBNcjIve+TK/MmpWxs8QHlKAi9wBVMI7mOZ5jz5Cf9DF5YSAqDsIqgm0nDRA== X-Received: by 2002:a92:d203:0:b0:323:891:6f27 with SMTP id y3-20020a92d203000000b0032308916f27mr560226ily.9.1679342573405; Mon, 20 Mar 2023 13:02:53 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id a17-20020a056e0208b100b00315785bfabfsm2998516ilt.47.2023.03.20.13.02.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 13:02:53 -0700 (PDT) Date: Mon, 20 Mar 2023 16:02:52 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Abhradeep Chakraborty , Jeff King Subject: [PATCH 5/6] pack-bitmap.c: use `bitmap_index_seek()` where possible Message-ID: <9a3e45b78b7810e0116848f1de80096b04285a55.1679342296.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As described in the previous commit, now that we have a functional `bitmap_index_seek()`, rewrite all callers that manually manipulate the `map_pos` variable with calls to `bitmap_index_seek()`. This means that all callers that adjust the value of `map_pos` have those changes automatically bounds- and overflow-checked. Signed-off-by: Taylor Blau --- pack-bitmap.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pack-bitmap.c b/pack-bitmap.c index fabcf01c14..38a3c6a3f9 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -174,7 +174,7 @@ static struct ewah_bitmap *read_bitmap_1(struct bitmap_index *index) return NULL; } - index->map_pos += bitmap_size; + bitmap_index_seek(index, bitmap_size, SEEK_CUR); return b; } @@ -230,7 +230,7 @@ static int load_bitmap_header(struct bitmap_index *index) index->entry_count = ntohl(header->entry_count); index->checksum = header->checksum; - index->map_pos += header_size; + bitmap_index_seek(index, header_size, SEEK_CUR); return 0; } @@ -269,13 +269,15 @@ static struct stored_bitmap *store_bitmap(struct bitmap_index *index, static uint32_t read_be32(struct bitmap_index *bitmap_git) { uint32_t result = get_be32(bitmap_git->map + bitmap_git->map_pos); - bitmap_git->map_pos += sizeof(result); + bitmap_index_seek(bitmap_git, sizeof(uint32_t), SEEK_CUR); return result; } static uint8_t read_u8(struct bitmap_index *bitmap_git) { - return bitmap_git->map[bitmap_git->map_pos++]; + uint8_t result = bitmap_git->map[bitmap_git->map_pos]; + bitmap_index_seek(bitmap_git, sizeof(uint8_t), SEEK_CUR); + return result; } #define MAX_XOR_OFFSET 160 @@ -794,14 +796,16 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_ while (xor_items_nr) { xor_item = &xor_items[xor_items_nr - 1]; - bitmap_git->map_pos = xor_item->offset; + bitmap_index_seek(bitmap_git, xor_item->offset, SEEK_SET); + if (bitmap_git->map_size - bitmap_git->map_pos < bitmap_header_size) { error(_("corrupt ewah bitmap: truncated header for bitmap of commit \"%s\""), oid_to_hex(&xor_item->oid)); goto corrupt; } - bitmap_git->map_pos += sizeof(uint32_t) + sizeof(uint8_t); + bitmap_index_seek(bitmap_git, + sizeof(uint32_t) + sizeof(uint8_t), SEEK_CUR); xor_flags = read_u8(bitmap_git); bitmap = read_bitmap_1(bitmap_git); @@ -812,7 +816,7 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_ xor_items_nr--; } - bitmap_git->map_pos = offset; + bitmap_index_seek(bitmap_git, offset, SEEK_SET); if (bitmap_git->map_size - bitmap_git->map_pos < bitmap_header_size) { error(_("corrupt ewah bitmap: truncated header for bitmap of commit \"%s\""), oid_to_hex(oid)); @@ -842,7 +846,8 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_ * Instead, we can skip ahead and immediately read the flags and * ewah bitmap. */ - bitmap_git->map_pos += sizeof(uint32_t) + sizeof(uint8_t); + bitmap_index_seek(bitmap_git, sizeof(uint32_t) + sizeof(uint8_t), + SEEK_CUR); flags = read_u8(bitmap_git); bitmap = read_bitmap_1(bitmap_git); From patchwork Mon Mar 20 20:02:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13181811 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96931C6FD1D for ; Mon, 20 Mar 2023 20:03:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231193AbjCTUDa (ORCPT ); Mon, 20 Mar 2023 16:03:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229847AbjCTUDW (ORCPT ); Mon, 20 Mar 2023 16:03:22 -0400 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09CE110F9 for ; Mon, 20 Mar 2023 13:02:57 -0700 (PDT) Received: by mail-il1-x131.google.com with SMTP id h11so7074848ild.11 for ; Mon, 20 Mar 2023 13:02:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; t=1679342576; 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=MWncWiA7gWVip1Q3SNRB5NqMi++Gucqu939gFHKmVhk=; b=ZGL0rDNJ9mPytjQrQiYur7V8NRkdRhe/ikTHKZhtXukSNjtitClBMq6kG0jvtPGV5b jkX5QFCNV4wvAIo/e/9nODiaeyE2JbUlcoxq6FdAIymjdKukddUHK07rSnyuw5iAm/zp 8mwl/yJ6BfsG938UtD/5HhIBi6K4Hb0obz8ATCZ7BldkgjA0Vj5KdWzrL0TNfzBg4EJC XwBIwTa/3K5oEjDnuD4/nTwBZq0oMJnXJRs2wla3Cnl85nb4beUuedPlg3hqfpkFL3iY s1TPXOMOQsBa+upGg50MZWRQPJ1AYosH6tY/c1PAdIuR94UWWqGxrQLqGuGCjVJmILHA mJLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679342576; 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=MWncWiA7gWVip1Q3SNRB5NqMi++Gucqu939gFHKmVhk=; b=bJMLFW3DdGvDcJpmA6IQzR4VRjYY2Fl1hey6MQGUHu9r4cyCIDwjHTTHh/SdJKsKCq 4sCtQjVWJPmY3jlVSyLchssZ+NS9foI4/sV5iOTHg98Aq1wwM75KStF/4aabCxB64v8C 0O0knE73D/RjSqoRRopdZKbXmJzOhoqS2epkvtvtOr+EntP1X5MxIhpn1DuGStZU3W3R iqDfuoRE/uxpuU2oBI85hxO7mwRVEtrbKTwJd4KCKJqrnnA6UzjxHp1moomsfeBBCWym 7C9ydoxO5Re/NrYvn4mc4+OILJOIsdiTHAXnfmRzLehfx2eUl8xHGy79h7Rn+4jz/QdP v2ww== X-Gm-Message-State: AO0yUKVGX+AbhWtSN1BoiPW1xlMCjdvNlAycqXeZWEmpZ+br7Zmuk+aw ZoAErsD0PBL2dme0/3ISjTtAFIM3AViix2gQLtzHAw== X-Google-Smtp-Source: AK7set9oT2UYUBZ4FFPA5oVaLGfZ26gcdZwPjjKAJ2gv7cNJ8eDlKBHTL3MoyVxqIEmSh2o40BKMFA== X-Received: by 2002:a92:da10:0:b0:316:e39f:1212 with SMTP id z16-20020a92da10000000b00316e39f1212mr550704ilm.4.1679342576067; Mon, 20 Mar 2023 13:02:56 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id g9-20020a025b09000000b0040610ade715sm3597861jab.83.2023.03.20.13.02.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 13:02:55 -0700 (PDT) Date: Mon, 20 Mar 2023 16:02:55 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Abhradeep Chakraborty , Jeff King Subject: [PATCH 6/6] pack-bitmap.c: factor out `bitmap_index_seek_commit()` Message-ID: <82049ed09e1695db644d1d4cf17557214e54dcea.1679342296.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Factor out a common pattern within `lazy_bitmap_for_commit()` where we seek to a given position (expecting to read the start of an individual bitmap entry). Both spots within `lazy_bitmap_for_commit()` emit a common error, so factor out the whole routine into its own function to DRY things up a little. Signed-off-by: Taylor Blau --- pack-bitmap.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/pack-bitmap.c b/pack-bitmap.c index 38a3c6a3f9..9859f61a5a 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -156,6 +156,21 @@ static size_t bitmap_index_seek(struct bitmap_index *bitmap_git, size_t offset, return bitmap_git->map_pos; } +static int bitmap_index_seek_commit(struct bitmap_index *bitmap_git, + struct object_id *oid, + size_t pos) +{ + const int bitmap_header_size = 6; + + bitmap_index_seek(bitmap_git, pos, SEEK_SET); + + if (bitmap_git->map_size - bitmap_git->map_pos < bitmap_header_size) + return error(_("corrupt ewah bitmap: truncated header for " + "bitmap of commit \"%s\""), + oid_to_hex(oid)); + return 0; +} + /* * Read a bitmap from the current read position on the mmaped * index, and increase the read position accordingly @@ -737,7 +752,6 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_ struct object_id *oid = &commit->object.oid; struct ewah_bitmap *bitmap; struct stored_bitmap *xor_bitmap = NULL; - const int bitmap_header_size = 6; static struct bitmap_lookup_table_xor_item *xor_items = NULL; static size_t xor_items_nr = 0, xor_items_alloc = 0; static int is_corrupt = 0; @@ -796,13 +810,10 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_ while (xor_items_nr) { xor_item = &xor_items[xor_items_nr - 1]; - bitmap_index_seek(bitmap_git, xor_item->offset, SEEK_SET); - if (bitmap_git->map_size - bitmap_git->map_pos < bitmap_header_size) { - error(_("corrupt ewah bitmap: truncated header for bitmap of commit \"%s\""), - oid_to_hex(&xor_item->oid)); + if (bitmap_index_seek_commit(bitmap_git, &xor_item->oid, + xor_item->offset) < 0) goto corrupt; - } bitmap_index_seek(bitmap_git, sizeof(uint32_t) + sizeof(uint8_t), SEEK_CUR); @@ -816,12 +827,8 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_ xor_items_nr--; } - bitmap_index_seek(bitmap_git, offset, SEEK_SET); - if (bitmap_git->map_size - bitmap_git->map_pos < bitmap_header_size) { - error(_("corrupt ewah bitmap: truncated header for bitmap of commit \"%s\""), - oid_to_hex(oid)); + if (bitmap_index_seek_commit(bitmap_git, oid, offset) < 0) goto corrupt; - } /* * Don't bother reading the commit's index position or its xor