sisong / ApkDiffPatch

a C++ library and command-line tools for Zip(Jar,Apk) file Diff & Patch; create minimal delta/differential; support Jar sign(apk v1 sign) & apk v2,v3 sign .
MIT License
310 stars 49 forks source link

patch fail with multi-thread #84

Closed jay-dh closed 2 years ago

jay-dh commented 2 years ago

ZipPatch & zip check always fail if enable multi-thread:

ZipPatch:

ApkDiffPatch|master⚡ ⇒ ./ZipPatch output/app_3.9.6.437.publish-arm64-v8a.apk output/app-patch.zip output/app_3.10.0.417.publish-arm64-v8a-normalized-signed-gen.apk -p-4
oldZip   :"output/app_3.9.6.437.publish-arm64-v8a.apk"
zipDiff  :"output/app-patch.zip"
outNewZip:"output/app_3.10.0.417.publish-arm64-v8a-normalized-signed-gen.apk"
  (NOTICE: _zlib_compress_part() is canceled, warning.)
Zipper_file_append_end(self->_out_newZip) ERROR!
_copy_same_file(self,pairNewiOldi[0],pairNewiOldi[1]) ERROR!
_NewStream_write(stream,writeToPos,data,data+leftLen) ERROR!
patch_decompress_with_cache(newStream.stream,oldStream.stream,zipDiffData.hdiffzData, decompressPlugin,temp_cache,temp_cache+HPATCH_CACHE_SIZE) PATCH_HPATCH_ERROR!
  (NOTICE: _zlib_compress_part() is canceled, warning.)
  zip file patch error!

ZipPatch time: 0.713 s

ZipDiff set thread num by -p-x not working, always enable multi-thread and will fail:

ApkDiffPatch|master⚡ ⇒ ./ZipDiff output/app_3.9.6.437.publish-arm64-v8a.apk output/app_3.10.0.417.publish-arm64-v8a-normalized-signed.apk output/app-patch.zip -p-1
oldZip  :"output/app_3.9.6.437.publish-arm64-v8a.apk"
newZip  :"output/app_3.10.0.417.publish-arm64-v8a-normalized-signed.apk"
outDiff :"output/app-patch.zip"
  NOTE: oldZip found JarSign(ApkV1Sign)
  NOTE: oldZip found ApkV2Sign
  NOTE: oldZip found ApkV3Sign
  NOTE: newZip maybe normalized
  NOTE: newZip found JarSign(ApkV1Sign)
  NOTE: newZip found ApkV2Sign
  NOTE: newZip found ApkV3Sign

ZipDiff with compress plugin: "lzma"
ZipDiff same file count: 2582 (all 4700)
    diff new file count: 2118
     ref old file count: 2845 (all 4666)
     ref old decompress: 2048 file (147505870 byte!)

run hdiffz:
  oldDataSize : 155234904
  newDataSize : 154425922
  (used one lzma dictSize: 2097152  (input data: 1609045))
  (used one lzma dictSize: 4194304  (input data: 11981908))
  (used one lzma dictSize: 4194304  (input data: 13503870))
  (used one lzma dictSize: 4194304  (input data: 24109222))
  diffDataSize: 19207752
  diff  time: 61.0609 s
  hpatchz check hdiffz result ok!
  patch time: 1.27717 s

  (used one lzma dictSize: 16384  (input data: 12302))
ZipDiff size: 19217140
ZipDiff time: 72.683 s

run ZipPatch:
  check ZipPatch result Byte By Byte Equal ok!
  patch time: 10.132 s (thread==1)
  (NOTICE: _zlib_compress_part() is canceled, warning.)
Zipper_file_append_end(self->_out_newZip) ERROR!
_copy_same_file(self,pairNewiOldi[0],pairNewiOldi[1]) ERROR!
_NewStream_write(stream,writeToPos,data,data+leftLen) ERROR!
patch_decompress_with_cache(newStream.stream,oldStream.stream,zipDiffData.hdiffzData, decompressPlugin,temp_cache,temp_cache+HPATCH_CACHE_SIZE) PATCH_HPATCH_ERROR!
  (NOTICE: _zlib_compress_part() is canceled, warning.)
  run ZipPatch ERROR!
  patch time: 0.689 s (thread==4)

all     time: 83.504 s

But it's fine if using single thread:

ApkDiffPatch|master⚡ ⇒ ./ZipPatch output/app_3.9.6.437.publish-arm64-v8a.apk output/app-patch.zip output/app_3.10.0.417.publish-arm64-v8a-normalized-signed-gen.apk
oldZip   :"output/app_3.9.6.437.publish-arm64-v8a.apk"
zipDiff  :"output/app-patch.zip"
outNewZip:"output/app_3.10.0.417.publish-arm64-v8a-normalized-signed-gen.apk"
  zip file patch ok!

ZipPatch time: 10.027 s
sisong commented 2 years ago

app_3.9.6.437.publish-arm64-v8a.apk must used apknormalized

jay-dh commented 2 years ago

great! it's finally succeeded after normalize the old apk !