git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jeff King <peff@peff.net>, John Hsing <tsyj2007@gmail.com>,
	Matthieu Moy <matthieu.moy@grenoble-inp.fr>,
	git@vger.kernel.org
Subject: Re: [PATCH] read-cache.c: fix index memory allocation
Date: Mon, 24 Oct 2011 17:52:57 +0200	[thread overview]
Message-ID: <4EA589D9.2000402@lsrfire.ath.cx> (raw)
In-Reply-To: <7vaa8q4zm9.fsf@alter.siamese.dyndns.org>

Am 24.10.2011 09:28, schrieb Junio C Hamano:
> René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:
> 
>>  t/t7510-status-index.sh |   50 +++++++++++++++++++++++++++++++++++++++++++++++
>>  2 files changed, 53 insertions(+), 3 deletions(-)
>>  create mode 100755 t/t7510-status-index.sh
> 
>> diff --git a/t/t7510-status-index.sh b/t/t7510-status-index.sh
>> new file mode 100755
>> index 0000000..bca359d
>> --- /dev/null
>> +++ b/t/t7510-status-index.sh
>> @@ -0,0 +1,50 @@
> 
> Hmm, I cannot seem to make this fail this test without the fix on my
> Fedora 14 i686 VM when applied to v1.7.6.4 (estimation code originates
> cf55870 back in v1.7.6.1 days), but it does break on 'master'.

Err, yes, I forgot to mention in the commit message that on my test
system the breakage occurs only after 2548183ba, "fix phantom untracked
files when core.ignorecase is set", which adds the pointer dir_next to
struct cache_entry.  This seems to have caused an unlucky constellation
of offsets and struct sizes for the size estimator.

> By the way, I'll move this to 7511.
> 
> Also would a patch like this help?

Only a little, I suspect.  If we've moved past the end then it's too
late.  And if we catch the error before it happens, dying is only
slightly better than crashing.

> -- >8 --
> Subject: [PATCH] read_index(): die on estimation error
> 
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  read-cache.c |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)
> 
> diff --git a/read-cache.c b/read-cache.c
> index 0a64103..2926615 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -1270,6 +1270,7 @@ int read_index_from(struct index_state *istate, const char *path)
>  	int fd, i;
>  	struct stat st;
>  	unsigned long src_offset, dst_offset;
> +	size_t bulk_alloc_size;
>  	struct cache_header *hdr;
>  	void *mmap;
>  	size_t mmap_size;
> @@ -1315,7 +1316,8 @@ int read_index_from(struct index_state *istate, const char *path)
>  	 * has room for a few  more flags, we can allocate using the same
>  	 * index size
>  	 */
> -	istate->alloc = xmalloc(estimate_cache_size(mmap_size, istate->cache_nr));
> +	bulk_alloc_size = estimate_cache_size(mmap_size, istate->cache_nr);
> +	istate->alloc = xmalloc(bulk_alloc_size);
>  	istate->initialized = 1;
>  
>  	src_offset = sizeof(*hdr);
> @@ -1331,7 +1333,9 @@ int read_index_from(struct index_state *istate, const char *path)
>  
>  		src_offset += ondisk_ce_size(ce);
>  		dst_offset += ce_size(ce);
> +		if (bulk_alloc_size <= dst_offset)
> +			die("cache size estimation error");
>  	}
>  	istate->timestamp.sec = st.st_mtime;
>  	istate->timestamp.nsec = ST_MTIME_NSEC(st);
>  

      reply	other threads:[~2011-10-24 15:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-22  0:20 a bug when execute "git status" in git version 1.7.7.431.g89633 John Hsing
2011-10-23  8:25 ` Matthieu Moy
2011-10-23  8:35   ` John Hsing
2011-10-23 13:25     ` René Scharfe
2011-10-23 14:28       ` René Scharfe
2011-10-23 16:29       ` Jeff King
2011-10-23 17:50         ` René Scharfe
2011-10-24  1:01           ` [PATCH] read-cache.c: fix index memory allocation René Scharfe
2011-10-24  7:07             ` Junio C Hamano
2011-10-24 15:59               ` René Scharfe
2011-10-24 21:59               ` René Scharfe
2011-10-24 23:34                 ` Nguyen Thai Ngoc Duy
2011-10-25  0:01                   ` Nguyen Thai Ngoc Duy
2011-10-25 18:00                     ` René Scharfe
2011-10-25 16:24                 ` Junio C Hamano
2011-10-24  7:28             ` Junio C Hamano
2011-10-24 15:52               ` René Scharfe [this message]

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=4EA589D9.2000402@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=matthieu.moy@grenoble-inp.fr \
    --cc=peff@peff.net \
    --cc=tsyj2007@gmail.com \
    /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).