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

Re: [PATCH] apply: reallocate the postimage buffer when needed

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 12, 2012, 06:23 UTC
Message-ID
<7v1uoyuyks.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vipiax3il.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 9 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
> ...
> But fixed_buf and fixed_len may be longer than the original length
> of preimage buffer when "indent must be spaces" is in effect, and
> that would mean context lines in the postimage may have to also
> grow. The call to update_pre_post_images() must be telling how big
> the postimage with fixed context lines will be, not passing 0 to say
> "I know it will not grow", because that is no longer true these
> days.

Just in case you haven't noticed it on your machine, t4105 shows that this patch breaks "git apply".

... ok 5 - big offset

expecting success: 
		git checkout-index -f -q -u file &&
		git apply -C2 F0.diff &&
		test_cmp expect file
	
Context reduced to (2/2) to apply fragment at 6
*** glibc detected *** /git.git/git: free(): invalid pointer: 0x00000000020c09e2 ***
...
./test-lib.sh: line 492: 10555 Aborted                 git apply -C2 F0.diff
not ok - 6 fuzz with no offset
#	
#			git checkout-index -f -q -u file &&
#			git apply -C2 F0.diff &&
#			test_cmp expect file
#		
With --valgrind the same test dies like so:

==18735== Invalid free() / delete / delete[] ==18735== at 0x4C240FD: free (vg_replace_malloc.c:366) ==18735== by 0x40918A: apply_data (apply.c:2692) ==18735== by 0x40A1C2: check_patch (apply.c:3163) ==18735== by 0x40C9A4: apply_patch (apply.c:3178) ==18735== by 0x40D9A1: cmd_apply (apply.c:3959) ==18735== by 0x404DD6: handle_internal_command (git.c:308) ==18735== by 0x404FFC: main (git.c:513) ==18735== Address 0x55c7c62 is 2 bytes inside a block of size 52 alloc'd ==18735== at 0x4C244E8: malloc (vg_replace_malloc.c:236) ==18735== by 0x4C24562: realloc (vg_replace_malloc.c:525) ==18735== by 0x4E19AD: xrealloc (wrapper.c:82) ==18735== by 0x4CFD7A: strbuf_grow (strbuf.c:72) ==18735== by 0x4082B6: apply_data (apply.c:2470) ==18735== by 0x40A1C2: check_patch (apply.c:3163) ==18735== by 0x40C9A4: apply_patch (apply.c:3178) ==18735== by 0x40D9A1: cmd_apply (apply.c:3959) ==18735== by 0x404DD6: handle_internal_command (git.c:308) ==18735== by 0x404FFC: main (git.c:513)

where "apply_data (apply.c:2692)" refers to 
	free(postimage.buf);
Previous: Junio C Hamano
Message 4 of 4 in “apply: reallocate the postimage buffer when needed”
  1. apply: reallocate the postimage buffer when neededCarlos Martín Nieto, Mar 11, 2012
  2. Junio C HamanoMar 11, 2012
  3. Junio C HamanoMar 11, 2012
  4. Junio C HamanoMar 12, 2012

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.