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

Re: [PATCH 3/6] wrapper: create safe_memory_limit_check()

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 21, 2026, 21:24 UTC
Message-ID
<xmqqzexal2lv.fsf@gitster.g>
In-Reply-To
<3b3c67243d200a42aa105981b64228e2cbb35a6c.1789736540.git.gitgitgadget@gmail.com>
"Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 11 quoted lines
> +static int safe_memory_limit_check(size_t size, int verbose)
>  {
> +	size_t limit = git_alloc_limit ? git_alloc_limit : SIZE_MAX;
> +	if (size > limit) {
> +		if (verbose)
>  			error("attempting to allocate %"PRIuMAX" over limit %"PRIuMAX,
>  			      (uintmax_t)size, (uintmax_t)git_alloc_limit);
> +		return -1;
>  	}
>  	return 0;
>  }

The code is prepared for a case where git_alloc_limit is set to 0, in which case SIZE_MAX is used as a stand-in value. When the check detects a request with overly large 'size', the error message tells us that 'size' is over 'git_alloc_limit', the latter is zero and any concrete value of 'size' certainly would be over that. Which may be a bit confusing.

Shouldn't we be giving the local "limit" instead in the message?
Previous: Derrick Stolee via GitGitGadgetNext: Derrick Stolee via GitGitGadget
Message 8 of 17 in “[RFC] Create a 'safe' strbuf API”
  1. 0/6 [RFC] Create a 'safe' strbuf APIDerrick Stolee via GitGitGadget, Sep 18, 2026
  2. 1/6 strbuf: add header for 'safe' APIDerrick Stolee via GitGitGadget, Sep 18, 2026
  3. Junio C HamanoSep 21, 2026
  4. Mark C. Chu-CarrollSep 23, 2026
  5. Junio C HamanoSep 23, 2026
  6. 2/6 wrapper: initialize GIT_ALLOC_LIMIT proactivelyDerrick Stolee via GitGitGadget, Sep 18, 2026
  7. 3/6 wrapper: create safe_memory_limit_check()Derrick Stolee via GitGitGadget, Sep 18, 2026
  8. Junio C HamanoSep 21, 2026
  9. 4/6 strbuf-safe: add sstrbuf_grow()Derrick Stolee via GitGitGadget, Sep 18, 2026
  10. Junio C HamanoSep 21, 2026
  11. 5/6 json-writer: include strbuf-safe.hDerrick Stolee via GitGitGadget, Sep 18, 2026
  12. 6/6 strbuf-safe: add init and release methodsDerrick Stolee via GitGitGadget, Sep 18, 2026
  13. Junio C HamanoSep 21, 2026
  14. Junio C HamanoSep 21, 2026
  15. Phillip WoodSep 19, 2026
  16. Jeff KingSep 23, 2026
  17. Derrick StoleeOct 6, 2026

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.