diff --git a/patch-delta.c b/patch-delta.c index 56e0a5ede2..b937afd2c9 100644 --- a/patch-delta.c +++ b/patch-delta.c @@ -56,7 +56,7 @@ void *patch_delta(const void *src_buf, unsigned long src_size, out += cp_size; size -= cp_size; } else if (cmd) { - if (cmd > size) + if (cmd > size || cmd > top - data) break; memcpy(out, data, cmd); out += cmd; diff --git a/t/t5303-pack-corruption-resilience.sh b/t/t5303-pack-corruption-resilience.sh index 912e659acf..7114c31ade 100755 --- a/t/t5303-pack-corruption-resilience.sh +++ b/t/t5303-pack-corruption-resilience.sh @@ -341,7 +341,7 @@ test_expect_success \ # \0 - empty base # \2 - two bytes in result # \2 - two literal bytes (we are short one) -test_expect_failure \ +test_expect_success \ 'apply delta with too few literal bytes' \ 'printf "\0\2\2X" > truncated_delta && test_must_fail test-tool delta -p /dev/null truncated_delta /dev/null'