fix a bug where we'd skip commands in the delta stream
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
diff --git a/lib/delta.c b/lib/delta.c
index 41af935..c7ae922 100644
--- a/lib/delta.c
+++ b/lib/delta.c
@@ -252,7 +252,7 @@ got_delta_apply(FILE *base_file, const uint8_t *delta_buf,
/* Decode and execute copy instructions from the delta stream. */
err = next_delta_byte(&p, &remain);
- while (err == NULL) {
+ while (err == NULL && remain > 0) {
if (*p & GOT_DELTA_BASE_COPY) {
off_t offset = 0;
size_t len = 0;
@@ -260,8 +260,13 @@ got_delta_apply(FILE *base_file, const uint8_t *delta_buf,
if (err)
break;
err = copy_from_base(base_file, offset, len, outfile);
- if (err == NULL)
+ if (err == NULL) {
outsize += len;
+ if (remain > 0) {
+ p++;
+ remain--;
+ }
+ }
} else {
size_t len = (size_t)*p;
if (len == 0) {
@@ -270,19 +275,11 @@ got_delta_apply(FILE *base_file, const uint8_t *delta_buf,
}
err = next_delta_byte(&p, &remain);
if (err)
- return err;
+ break;
err = copy_from_delta(&p, &remain, len, outfile);
if (err == NULL)
outsize += len;
}
-
- if (err == NULL) {
- if (remain == 0)
- break;
- /* Fetch the next instruction. */
- p++;
- remain--;
- }
}
if (outsize != result_size)