git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Ensure __BYTE_ORDER is always set

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jan 31, 2014, 02:35 UTC
Message-ID
<CAPig+cS-ae3PGPGAAam6oKnFS4SxUOg2RE_7aUJrMyqE+sZvvw@mail.gmail.com>
In-Reply-To
<20140130215002.GB1130@sigill.intra.peff.net>
On Thu, Jan 30, 2014 at 4:50 PM, Jeff King <peff@peff.net> wrote:
Show 22 quoted lines
> I think we could do this with something like the patch below, which
> checks two things:
>
>   1. When we expand the ewah, it has the same number of bits we claimed
>      in the on-disk header.
>
>   2. The ewah header matches the number of objects in the packfile.
>
> The first catches a corruption in the ewah data itself, and the latter
> when the header is corrupted. You can test either by breaking the
> endian-swapping. :)
>
> diff --git a/pack-bitmap.c b/pack-bitmap.c
> index ae0b57b..a31e529 100644
> --- a/pack-bitmap.c
> +++ b/pack-bitmap.c
> @@ -130,6 +131,31 @@ static struct ewah_bitmap *read_bitmap_1(struct bitmap_index *index)
>                 return NULL;
>         }
>
> +       /*
> +        * It's OK for us to have too fewer bits than objects, as the EWAH
s/fewer/few/
Show 27 quoted lines
> +        * writer may have simply left off an ending that is all-zeroes.
> +        *
> +        * However it's not OK for us to have too many bits, as that would
> +        * entail touching objects that we don't have. We are careful
> +        * enough to avoid doing so in later code, but in the case of
> +        * nonsensical values, we would want to avoid even allocating
> +        * memory to hold the expanded bitmap.
> +        *
> +        * There is one exception: we may "go over" to round up to the next
> +        * 64-bit ewah word, since the storage comes in chunks of that size.
> +        */
> +       expected_bits = index->pack->num_objects;
> +       if (expected_bits & 63) {
> +               expected_bits &= ~63;
> +               expected_bits += 64;
> +       }
> +       if (b->bit_size > expected_bits) {
> +               error("unexpected number of bits in bitmap: %"PRIuMAX" > %"PRIuMAX,
> +                     (uintmax_t)b->bit_size, (uintmax_t)expected_bits);
> +               ewah_pool_free(b);
> +               return NULL;
> +       }
> +
>         index->map_pos += bitmap_size;
>         return b;
>  }
> --
Previous: Jeff KingNext: Jonathan Nieder
Message 4 of 9 in “Ensure __BYTE_ORDER is always set”
  1. Ensure __BYTE_ORDER is always setBrian Gernhardt, Jan 30, 2014
  2. Jeff KingJan 30, 2014
  3. Jeff KingJan 30, 2014
  4. Eric SunshineJan 31, 2014
  5. Jonathan NiederJan 30, 2014
  6. Jeff KingJan 30, 2014
  7. Brian GernhardtJan 30, 2014
  8. Jonathan NiederJan 30, 2014
  9. Jeff KingJan 30, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.