mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
patch-delta: consistently report corruption
When applying a delta, if we see an opcode that cannot be fulfilled (e.g., asking to write more bytes than the destination has left), we break out of our parsing loop but don't signal an explicit error. We rely on the sanity check after the loop to see if we have leftover delta bytes or didn't fill our result buffer. This can silently ignore corruption when the delta buffer ends with a bogus command and the destination buffer is already full. Instead, let's jump into the error handler directly when we see this case. Note that the tests also cover the "bad opcode" case, which already handles this correctly. Signed-off-by: Jann Horn <jannh@google.com> Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Nicolas Pitre <nico@fluxnic.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
21870efc4a
commit
fa72f90e7a
@@ -51,13 +51,13 @@ void *patch_delta(const void *src_buf, unsigned long src_size,
|
||||
if (unsigned_add_overflows(cp_off, cp_size) ||
|
||||
cp_off + cp_size > src_size ||
|
||||
cp_size > size)
|
||||
break;
|
||||
goto bad_length;
|
||||
memcpy(out, (char *) src_buf + cp_off, cp_size);
|
||||
out += cp_size;
|
||||
size -= cp_size;
|
||||
} else if (cmd) {
|
||||
if (cmd > size || cmd > top - data)
|
||||
break;
|
||||
goto bad_length;
|
||||
memcpy(out, data, cmd);
|
||||
out += cmd;
|
||||
data += cmd;
|
||||
@@ -75,6 +75,7 @@ void *patch_delta(const void *src_buf, unsigned long src_size,
|
||||
|
||||
/* sanity check */
|
||||
if (data != top || size != 0) {
|
||||
bad_length:
|
||||
error("delta replay has gone wild");
|
||||
bad:
|
||||
free(dst_buf);
|
||||
|
||||
Reference in New Issue
Block a user