improve error reporting when delta application fails
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
diff --git a/lib/delta.c b/lib/delta.c
index d261659..e3ee8c6 100644
--- a/lib/delta.c
+++ b/lib/delta.c
@@ -80,7 +80,8 @@ static const struct got_error *
next_delta_byte(const uint8_t **p, size_t *remain)
{
if (--(*remain) == 0)
- return got_error(GOT_ERR_BAD_DELTA);
+ return got_error_msg(GOT_ERR_BAD_DELTA,
+ "delta data truncated");
(*p)++;
return NULL;
}
@@ -206,7 +207,8 @@ copy_from_delta(const uint8_t **p, size_t *remain, size_t len, FILE *outfile)
size_t n;
if (*remain < len)
- return got_error(GOT_ERR_BAD_DELTA);
+ return got_error_msg(GOT_ERR_BAD_DELTA,
+ "copy from beyond end of delta data");
n = fwrite(*p, len, 1, outfile);
if (n != 1)
@@ -245,7 +247,7 @@ got_delta_get_sizes(uint64_t *base_size, uint64_t *result_size,
const uint8_t *p;
if (delta_len < GOT_DELTA_STREAM_LENGTH_MIN)
- return got_error(GOT_ERR_BAD_DELTA);
+ return got_error_msg(GOT_ERR_BAD_DELTA, "delta too small");
p = delta_buf;
remain = delta_len;
@@ -265,7 +267,7 @@ got_delta_apply_in_mem(uint8_t *base_buf, size_t base_bufsz,
*outsize= 0;
if (delta_len < GOT_DELTA_STREAM_LENGTH_MIN)
- return got_error(GOT_ERR_BAD_DELTA);
+ return got_error_msg(GOT_ERR_BAD_DELTA, "delta too small");
p = delta_buf;
remain = delta_len;
@@ -285,7 +287,8 @@ got_delta_apply_in_mem(uint8_t *base_buf, size_t base_bufsz,
if (SIZE_MAX - offset < len || offset + len < 0 ||
base_bufsz < offset + len ||
*outsize + len > maxoutsize)
- return got_error(GOT_ERR_BAD_DELTA);
+ return got_error_msg(GOT_ERR_BAD_DELTA,
+ "bad delta copy length");
memcpy(outbuf + *outsize, base_buf + offset, len);
if (err == NULL) {
*outsize += len;
@@ -297,7 +300,8 @@ got_delta_apply_in_mem(uint8_t *base_buf, size_t base_bufsz,
} else {
size_t len = (size_t)*p;
if (len == 0) {
- err = got_error(GOT_ERR_BAD_DELTA);
+ err = got_error_msg(GOT_ERR_BAD_DELTA,
+ "zero length delta");
break;
}
err = next_delta_byte(&p, &remain);
@@ -305,7 +309,8 @@ got_delta_apply_in_mem(uint8_t *base_buf, size_t base_bufsz,
break;
if (remain < len || SIZE_MAX - *outsize < len ||
*outsize + len > maxoutsize)
- return got_error(GOT_ERR_BAD_DELTA);
+ return got_error_msg(GOT_ERR_BAD_DELTA,
+ "bad delta copy length");
memcpy(outbuf + *outsize, p, len);
p += len;
remain -= len;
@@ -314,7 +319,8 @@ got_delta_apply_in_mem(uint8_t *base_buf, size_t base_bufsz,
}
if (*outsize != result_size)
- err = got_error(GOT_ERR_BAD_DELTA);
+ err = got_error_msg(GOT_ERR_BAD_DELTA,
+ "delta application result size mismatch");
return err;
}
@@ -333,7 +339,7 @@ got_delta_apply(FILE *base_file, const uint8_t *delta_buf,
*outsize = 0;
if (delta_len < GOT_DELTA_STREAM_LENGTH_MIN)
- return got_error(GOT_ERR_BAD_DELTA);
+ return got_error_msg(GOT_ERR_BAD_DELTA, "delta too small");
p = delta_buf;
remain = delta_len;
@@ -365,7 +371,8 @@ got_delta_apply(FILE *base_file, const uint8_t *delta_buf,
} else {
size_t len = (size_t)*p;
if (len == 0) {
- err = got_error(GOT_ERR_BAD_DELTA);
+ err = got_error_msg(GOT_ERR_BAD_DELTA,
+ "zero length delta");
break;
}
err = next_delta_byte(&p, &remain);
@@ -379,7 +386,8 @@ got_delta_apply(FILE *base_file, const uint8_t *delta_buf,
}
if (*outsize != result_size)
- err = got_error(GOT_ERR_BAD_DELTA);
+ err = got_error_msg(GOT_ERR_BAD_DELTA,
+ "delta application result size mismatch");
if (memstream != NULL) {
if (fclose(memstream) == EOF)