• Jeff King's avatar
    apply: don't segfault on binary files with missing data · 24305cd7
    Jeff King authored
    Usually when applying a binary diff generated without
    --binary, it will be rejected early, as we don't even have
    the full sha1 of the pre- and post-images.
    
    However, if the diff is generated with --full-index (but not
    --binary), then we will actually try to apply it. If we have
    the postimage blob, then we can take a shortcut and never
    even look at the binary diff at all (e.g., this can happen
    when rebasing changes within a repository).
    
    If we don't have the postimage blob, though, we try to look
    at the actual fragments, of which there are none, and get a
    segfault. This patch checks explicitly for that case and
    complains to the user instead of segfaulting. We need to
    keep the check at a low level so that the "shortcut" case
    above continues to work.
    
    We also add a test that demonstrates the segfault. While
    we're at it, let's also explicitly test the shortcut case.
    Reported-by: default avatarRafaël Carré <rafael.carre@gmail.com>
    Signed-off-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    24305cd7
apply.c 98.3 KB