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

Re: [PATCH 2/3] imap-send: be more careful when casting to `curl_off_t`

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 21, 2025, 15:06 UTC
Message-ID
<xmqqbjn3x2u5.fsf@gitster.g>
In-Reply-To
<e1d5a85f70c514749304fe87efde271e9ed5a92c.1758457356.git.gitgitgadget@gmail.com>

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:

Show 5 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> When casting a `size_t` to `curl_off_t`, there is a currently uncommon
> chance that the value can be cut off (`curl_off_t` is supposed to be
> guaranteed to be 64-bit).

"64-bit" -> "signed 64-bit", per what <curl/system.h> says, i.e. "curl_off_t MUST be typedef'ed to a 64-bit * wide signed integral data type.", perhaps?

msgbuf.buf is a strbuf, so its .len member is of size_t (so is prev_len); prev_len is how big the msgbuf.buf was before the code added some stuff taken from all_msgs, possibly wrapping the result in html, and converting lf to crlf, all only enlarging the buffer. We are computing how much we bloated the msgbuf.buf relative to the original here, so this subtraction should not suffer unsigned wraparound. Now thanks to the previous step, we can consistently and safely cast size_t values to curl_off_t easily, which is nice.

Looking good.  Will queue.  Thanks.
Show 12 quoted lines
> diff --git a/imap-send.c b/imap-send.c
> index 4bd5b8aa0d..26dda7f328 100644
> --- a/imap-send.c
> +++ b/imap-send.c
> @@ -1721,7 +1721,7 @@ static int curl_append_msgs_to_imap(struct imap_server_conf *server,
>  		lf_to_crlf(&msgbuf.buf);
>  
>  		curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
> -				 (curl_off_t)(msgbuf.buf.len-prev_len));
> +				 cast_size_t_to_curl_off_t(msgbuf.buf.len-prev_len));
>  
>  		res = curl_easy_perform(curl);
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin via GitGitGadget
Message 5 of 12 in “Fix curl_easy_setopt() parameter type problem, again”
  1. 0/3 Fix curl_easy_setopt() parameter type problem, againJohannes Schindelin via GitGitGadget, Sep 21, 2025
  2. 1/3 http: offer to cast `size_t` to `curl_off_t` safelyJohannes Schindelin via GitGitGadget, Sep 21, 2025
  3. Junio C HamanoSep 21, 2025
  4. 2/3 imap-send: be more careful when casting to `curl_off_t`Johannes Schindelin via GitGitGadget, Sep 21, 2025
  5. Junio C HamanoSep 21, 2025
  6. 3/3 http-push: avoid new compile errorJohannes Schindelin via GitGitGadget, Sep 21, 2025
  7. Junio C HamanoSep 21, 2025
  8. 0/3 Fix curl_easy_setopt() parameter type problem, againJohannes Schindelin via GitGitGadget, Sep 26, 2025
  9. 1/3 http: offer to cast `size_t` to `curl_off_t` safelyJohannes Schindelin via GitGitGadget, Sep 26, 2025
  10. 2/3 imap-send: be more careful when casting to `curl_off_t`Johannes Schindelin via GitGitGadget, Sep 26, 2025
  11. 3/3 http-push: avoid new compile errorJohannes Schindelin via GitGitGadget, Sep 26, 2025
  12. Junio C HamanoSep 26, 2025

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.