From: Junio C Hamano <gitster@pobox.com>
To: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH 2/3] imap-send: be more careful when casting to `curl_off_t`
Date: Sun, 21 Sep 2025 08:06:10 -0700 [thread overview]
Message-ID: <xmqqbjn3x2u5.fsf@gitster.g> (raw)
In-Reply-To: <e1d5a85f70c514749304fe87efde271e9ed5a92c.1758457356.git.gitgitgadget@gmail.com> (Johannes Schindelin via GitGitGadget's message of "Sun, 21 Sep 2025 12:22:35 +0000")
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
writes:
> 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.
> 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);
next prev parent reply other threads:[~2025-09-21 15:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-21 12:22 [PATCH 0/3] Fix curl_easy_setopt() parameter type problem, again Johannes Schindelin via GitGitGadget
2025-09-21 12:22 ` [PATCH 1/3] http: offer to cast `size_t` to `curl_off_t` safely Johannes Schindelin via GitGitGadget
2025-09-21 14:52 ` Junio C Hamano
2025-09-21 12:22 ` [PATCH 2/3] imap-send: be more careful when casting to `curl_off_t` Johannes Schindelin via GitGitGadget
2025-09-21 15:06 ` Junio C Hamano [this message]
2025-09-21 12:22 ` [PATCH 3/3] http-push: avoid new compile error Johannes Schindelin via GitGitGadget
2025-09-21 15:09 ` Junio C Hamano
2025-09-26 10:32 ` [PATCH v2 0/3] Fix curl_easy_setopt() parameter type problem, again Johannes Schindelin via GitGitGadget
2025-09-26 10:32 ` [PATCH v2 1/3] http: offer to cast `size_t` to `curl_off_t` safely Johannes Schindelin via GitGitGadget
2025-09-26 10:32 ` [PATCH v2 2/3] imap-send: be more careful when casting to `curl_off_t` Johannes Schindelin via GitGitGadget
2025-09-26 10:32 ` [PATCH v2 3/3] http-push: avoid new compile error Johannes Schindelin via GitGitGadget
2025-09-26 17:40 ` [PATCH v2 0/3] Fix curl_easy_setopt() parameter type problem, again Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqbjn3x2u5.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=johannes.schindelin@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).