From: Junio C Hamano <gitster@pobox.com>
To: Martin Koegler <martin.koegler@chello.at>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Fix delta integer overflows
Date: Mon, 07 Aug 2017 11:36:29 -0700 [thread overview]
Message-ID: <xmqq1sonql76.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <1502129437-31226-1-git-send-email-martin@mail.zuhause> (Martin Koegler's message of "Mon, 7 Aug 2017 20:10:37 +0200")
Martin Koegler <martin.koegler@chello.at> writes:
> From: Martin Koegler <martin.koegler@chello.at>
>
> The current delta code produces incorrect pack objects for files > 4GB.
>
> Signed-off-by: Martin Koegler <martin.koegler@chello.at>
> ---
> diff-delta.c | 23 ++++++++++++-----------
> 1 file changed, 12 insertions(+), 11 deletions(-)
>
> Just pass any file > 4 GB to the delta-compression [by increasing the delta limits].
> As file size, a truncated 32bit value will be encoded, leading to broken pack files.
The patch obviously makes the code better and self consistent in
that "struct delta_index" has src_size as ulong, and this function
takes trg_size as ulong, and it was plain wrong for the code to
assume that "i", which is uint, can receive it safely.
In the longer term we might want to move to size_t or even
uintmax_t, as the ulong on a platform may not be long enough in
order to express the largest file size the platform can have, but
this patch (1) is good even without such a change, and (2) gives a
good foundation to build on if we want such a change on top.
Thanks. Will queue.
>
> diff --git a/diff-delta.c b/diff-delta.c
> index 3797ce6..13e5a01 100644
> --- a/diff-delta.c
> +++ b/diff-delta.c
> @@ -319,7 +319,8 @@ create_delta(const struct delta_index *index,
> const void *trg_buf, unsigned long trg_size,
> unsigned long *delta_size, unsigned long max_size)
> {
> - unsigned int i, outpos, outsize, moff, msize, val;
> + unsigned int i, val;
> + unsigned long l, outpos, outsize, moff, msize;
> int inscnt;
> const unsigned char *ref_data, *ref_top, *data, *top;
> unsigned char *out;
> @@ -336,20 +337,20 @@ create_delta(const struct delta_index *index,
> return NULL;
>
> /* store reference buffer size */
> - i = index->src_size;
> - while (i >= 0x80) {
> - out[outpos++] = i | 0x80;
> - i >>= 7;
> + l = index->src_size;
> + while (l >= 0x80) {
> + out[outpos++] = l | 0x80;
> + l >>= 7;
> }
> - out[outpos++] = i;
> + out[outpos++] = l;
>
> /* store target buffer size */
> - i = trg_size;
> - while (i >= 0x80) {
> - out[outpos++] = i | 0x80;
> - i >>= 7;
> + l = trg_size;
> + while (l >= 0x80) {
> + out[outpos++] = l | 0x80;
> + l >>= 7;
> }
> - out[outpos++] = i;
> + out[outpos++] = l;
>
> ref_data = index->src_buf;
> ref_top = ref_data + index->src_size;
next prev parent reply other threads:[~2017-08-07 18:36 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-07 18:10 [PATCH] Fix delta integer overflows Martin Koegler
2017-08-07 18:36 ` Junio C Hamano [this message]
2017-08-07 19:39 ` Johannes Schindelin
2017-08-07 19:48 ` Junio C Hamano
2017-08-07 21:10 ` Johannes Schindelin
2017-08-07 21:36 ` Junio C Hamano
2017-08-07 23:02 ` Junio C Hamano
2017-08-08 6:20 ` Martin Koegler
2017-08-08 11:38 ` Johannes Schindelin
2017-08-08 1:44 ` Junio C Hamano
2017-08-08 6:25 ` Martin Koegler
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=xmqq1sonql76.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=martin.koegler@chello.at \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.