diff --git a/cab.c b/cab.c index e09970e..479a81a 100644 --- a/cab.c +++ b/cab.c @@ -556,8 +556,9 @@ static void cab_update_data_size(FILE_FORMAT_CTX *ctx, BIO *outdata, PKCS7 *p7) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - if (ctx->options->cmd == CMD_VERIFY || ctx->options->cmd == CMD_EXTRACT - || ctx->options->cmd == CMD_REMOVE) { + if (!p7) { + /* CMD_REMOVE + * additional header does not exist so additional data size is unused */ return; } (void)BIO_seek(outdata, 0x30); diff --git a/osslsigncode.c b/osslsigncode.c index 607e960..1d9d3d4 100644 --- a/osslsigncode.c +++ b/osslsigncode.c @@ -3547,6 +3547,9 @@ int main(int argc, char **argv) goto skip_signing; } else if (options.cmd == CMD_REMOVE && ctx->format->remove_pkcs7) { ret = ctx->format->remove_pkcs7(ctx, hash, outdata); + if (ctx->format->update_data_size) { + ctx->format->update_data_size(ctx, outdata, NULL); + } goto skip_signing; } else if (ctx->format->pkcs7_prepare) { p7 = ctx->format->pkcs7_prepare(ctx, hash, outdata); diff --git a/pe.c b/pe.c index 76f8dd6..4d62b15 100644 --- a/pe.c +++ b/pe.c @@ -519,10 +519,7 @@ static void pe_update_data_size(FILE_FORMAT_CTX *ctx, BIO *outdata, PKCS7 *p7) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - if (ctx->options->cmd == CMD_VERIFY || ctx->options->cmd == CMD_EXTRACT) { - return; - } - if (ctx->options->cmd != CMD_REMOVE) { + if (p7) { int len = i2d_PKCS7(p7, NULL); int padlen = len % 8 ? 8 - len % 8 : 0; @@ -534,9 +531,10 @@ static void pe_update_data_size(FILE_FORMAT_CTX *ctx, BIO *outdata, PKCS7 *p7) BIO_write(outdata, buf, 4); PUT_UINT32_LE(len + 8 + padlen, buf); BIO_write(outdata, buf, 4); - } - checksum = pe_calc_checksum(outdata, ctx->pe_ctx->header_size); + } /* else CMD_REMOVE */ + /* write back checksum */ + checksum = pe_calc_checksum(outdata, ctx->pe_ctx->header_size); (void)BIO_seek(outdata, ctx->pe_ctx->header_size + 88); PUT_UINT32_LE(checksum, buf); BIO_write(outdata, buf, 4);