Re: [PATCH] apply: reallocate the postimage buffer when needed
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:53:16
Junio C Hamano [off-list ref] writes:
Junio C Hamano [off-list ref] 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);