@ -198,8 +198,7 @@ static long apply_delta(off_t len, struct line_buffer *input,
const char *old_data, uint32_t old_mode)
const char *old_data, uint32_t old_mode)
{
{
long ret;
long ret;
off_t preimage_len = 0;
struct sliding_view preimage = SLIDING_VIEW_INIT(&report_buffer, 0);
struct sliding_view preimage = SLIDING_VIEW_INIT(&report_buffer, -1);
FILE *out;
FILE *out;
if (init_postimage() || !(out = buffer_tmpfile_rewind(&postimage)))
if (init_postimage() || !(out = buffer_tmpfile_rewind(&postimage)))
@ -211,19 +210,23 @@ static long apply_delta(off_t len, struct line_buffer *input,
printf("cat-blob %s\n", old_data);
printf("cat-blob %s\n", old_data);
fflush(stdout);
fflush(stdout);
response = get_response_line();
response = get_response_line();
if (parse_cat_response_line(response, &preimage_len))
if (parse_cat_response_line(response, &preimage.max_off))
die("invalid cat-blob response: %s", response);
die("invalid cat-blob response: %s", response);
check_preimage_overflow(preimage.max_off, 1);
}
}
if (old_mode == REPO_MODE_LNK) {
if (old_mode == REPO_MODE_LNK) {
strbuf_addstr(&preimage.buf, "link ");
strbuf_addstr(&preimage.buf, "link ");
check_preimage_overflow(preimage_len, strlen("link "));
check_preimage_overflow(preimage.max_off, strlen("link "));
preimage_len += strlen("link ");
preimage.max_off += strlen("link ");
check_preimage_overflow(preimage.max_off, 1);
}
}
if (svndiff0_apply(input, len, &preimage, out))
if (svndiff0_apply(input, len, &preimage, out))
die("cannot apply delta");
die("cannot apply delta");
if (old_data) {
if (old_data) {
/* Read the remainder of preimage and trailing newline. */
/* Read the remainder of preimage and trailing newline. */
if (move_window(&preimage, preimage_len, 1))
assert(!signed_add_overflows(preimage.max_off, 1));
preimage.max_off++; /* room for newline */
if (move_window(&preimage, preimage.max_off - 1, 1))
die("cannot seek to end of input");
die("cannot seek to end of input");
if (preimage.buf.buf[0] != '\n')
if (preimage.buf.buf[0] != '\n')
die("missing newline after cat-blob response");
die("missing newline after cat-blob response");