Fixed corner case delta bug when matching across old/new sector

pull/166/head
Daniele Lacamera 2021-12-30 12:23:44 +01:00
parent 78ace2ee17
commit c76166f6ea
1 changed files with 12 additions and 9 deletions

View File

@ -229,14 +229,15 @@ int wb_diff(WB_DIFF_CTX *ctx, uint8_t *patch, uint32_t len)
pa+= BLOCK_HDR_SIZE; pa+= BLOCK_HDR_SIZE;
ctx->off_b += BLOCK_HDR_SIZE; ctx->off_b += BLOCK_HDR_SIZE;
while (*pa == *(ctx->src_b + ctx->off_b)) { while (*pa == *(ctx->src_b + ctx->off_b)) {
match_len++; if ((uint32_t)(pa + 1 - ctx->src_a) >= ctx->size_a) {
pa++;
ctx->off_b++;
if ((uint32_t)(pa - ctx->src_a) >= ctx->size_a)
break;
if ((b_start / WOLFBOOT_SECTOR_SIZE) < (ctx->off_b / WOLFBOOT_SECTOR_SIZE)) {
break; break;
} }
if ((b_start / WOLFBOOT_SECTOR_SIZE) < ((ctx->off_b + 1) / WOLFBOOT_SECTOR_SIZE)) {
break;
}
pa++;
ctx->off_b++;
match_len++;
} }
hdr.esc = ESC; hdr.esc = ESC;
hdr.off[0] = ((blk_start >> 16) & 0x000000FF); hdr.off[0] = ((blk_start >> 16) & 0x000000FF);
@ -268,11 +269,13 @@ int wb_diff(WB_DIFF_CTX *ctx, uint8_t *patch, uint32_t len)
pb+= BLOCK_HDR_SIZE; pb+= BLOCK_HDR_SIZE;
ctx->off_b += BLOCK_HDR_SIZE; ctx->off_b += BLOCK_HDR_SIZE;
while (*pb == *(ctx->src_b + ctx->off_b)) { while (*pb == *(ctx->src_b + ctx->off_b)) {
match_len++;
pb++; pb++;
ctx->off_b++; if ((uint32_t)(pb - ctx->src_b) >= pb_end) {
if ((uint32_t)(pb - ctx->src_b) >= pb_end) pb--;
break; break;
}
match_len++;
ctx->off_b++;
} }
hdr.esc = ESC; hdr.esc = ESC;
hdr.off[0] = ((blk_start >> 16) & 0x000000FF); hdr.off[0] = ((blk_start >> 16) & 0x000000FF);