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

Re: [PATCH 3/9] Convert unpack-objects to size_t

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Aug 12, 2017, 14:07 UTC
Message-ID
<CAN0heSpViT-Nz8OO7Bww3Fbm=mzA6wvm0EfgfRjsz+cVfvu3Yw@mail.gmail.com>
In-Reply-To
<1502527643-21944-3-git-send-email-martin@mail.zuhause>
On 12 August 2017 at 10:47, Martin Koegler <martin.koegler@chello.at> wrote:
Show 38 quoted lines
> From: Martin Koegler <martin.koegler@chello.at>
>
> Signed-off-by: Martin Koegler <martin.koegler@chello.at>
> ---
>  builtin/unpack-objects.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
> index 001dd4b..0d8b6b3 100644
> --- a/builtin/unpack-objects.c
> +++ b/builtin/unpack-objects.c
> @@ -31,7 +31,7 @@ static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
>   */
>  struct obj_buffer {
>         char *buffer;
> -       unsigned long size;
> +       size_t size;
>  };
>
>  static struct decoration obj_decorate;
> @@ -41,7 +41,7 @@ static struct obj_buffer *lookup_object_buffer(struct object *base)
>         return lookup_decoration(&obj_decorate, base);
>  }
>
> -static void add_object_buffer(struct object *object, char *buffer, unsigned long size)
> +static void add_object_buffer(struct object *object, char *buffer, size_t size)
>  {
>         struct obj_buffer *obj;
>         obj = xcalloc(1, sizeof(struct obj_buffer));
> @@ -93,7 +93,7 @@ static void use(int bytes)
>                 die(_("pack exceeds maximum allowed size"));
>  }
>
> -static void *get_data(unsigned long size)
> +static void *get_data(size_t size)
>  {
>         git_zstream stream;
>         void *buf = xmallocz(size);

"size" is handed over to a "git_zstream" and goes through zlib.c, eventually ending up in zlib, which is outside Git's control, and which seems to work with "uLong"s. How do these kind of changes interact with zlib? For example, I wonder about this line further down in get_data:

if (stream.total_out == size && ret == Z_STREAM_END)

If total_out isn't converted, I guess this would never hit if "size" is too large. And if total_out /is/ converted, I guess we'd risk truncation in zlib_pre_call in zlib.c. Maybe that might cause Git and zlib to have different ideas about how much data is available and/or should be processed. Maybe we could then hit things like this in git.c:

if (s->z.total_out != s->total_out + bytes_produced)
        die("BUG: total_out mismatch");
I am not very familiar with zlib, so apologies if this is just noise...
Martin
Previous: Martin KoeglerNext: Martin Koegler
Message 4 of 27 in “Convert pack-objects to size_t”
  1. 1/9 Convert pack-objects to size_tMartin Koegler, Aug 12, 2017
  2. 4/9 Convert archive functions to size_tMartin Koegler, Aug 12, 2017
  3. 3/9 Convert unpack-objects to size_tMartin Koegler, Aug 12, 2017
  4. Martin ÅgrenAug 12, 2017
  5. Martin KoeglerAug 13, 2017
  6. 8/9 Convert tree-walk to size_tMartin Koegler, Aug 12, 2017
  7. 5/9 Convert various things to size_tMartin Koegler, Aug 12, 2017
  8. Martin ÅgrenAug 12, 2017
  9. Martin KoeglerAug 13, 2017
  10. 7/9 Convert ref-filter to size_tMartin Koegler, Aug 12, 2017
  11. 9/9 Convert xdiff-interface to size_tMartin Koegler, Aug 12, 2017
  12. 6/9 Use size_t for config parsingMartin Koegler, Aug 12, 2017
  13. 2/9 Convert index-pack to size_tMartin Koegler, Aug 12, 2017
  14. Ramsay JonesAug 12, 2017
  15. Torsten BögershausenAug 12, 2017
  16. Martin KoeglerAug 13, 2017
  17. Ramsay JonesAug 12, 2017
  18. Martin KoeglerAug 13, 2017
  19. Ramsay JonesAug 13, 2017
  20. Junio C HamanoAug 13, 2017
  21. Junio C HamanoAug 14, 2017
  22. Ramsay JonesAug 14, 2017
  23. Junio C HamanoAug 14, 2017
  24. Torsten BögershausenAug 14, 2017
  25. Ramsay JonesAug 15, 2017
  26. Martin KoeglerAug 16, 2017
  27. Torsten BögershausenAug 17, 2017

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.