diff --git a/services/package/pkg_package/pkg_upgradefile.cpp b/services/package/pkg_package/pkg_upgradefile.cpp index 85d4e1e03477cfa5008d17a0e7297b454725572a..72e466ea0305225c3db9c29d6cf1d2fa1a561707 100644 --- a/services/package/pkg_package/pkg_upgradefile.cpp +++ b/services/package/pkg_package/pkg_upgradefile.cpp @@ -326,6 +326,11 @@ int32_t UpgradePkgFile::ReadUpgradePkgHeader(const PkgBuffer &buffer, size_t &re PkgFile::ConvertBufferToString(pkgInfo_.productUpdateId, {header->productUpdateId, sizeof(header->productUpdateId)}); + algorithm = PkgAlgorithmFactory::GetDigestAlgorithm(pkgInfo_.pkgInfo.digestMethod); + PKG_CHECK(algorithm != nullptr, return PKG_NOT_EXIST_ALGORITHM, + "Invalid file %s", pkgStream_->GetFileName().c_str()); + algorithm->Init(); + if (currLen + tlv.length >= readLen) { // Extra TLV information, read it. realLen = currLen + tlv.length; algorithm->Update(buffer, realLen); @@ -348,10 +353,6 @@ int32_t UpgradePkgFile::ReadUpgradePkgHeader(const PkgBuffer &buffer, size_t &re realLen += currLen; // Parser header to get compressional algorithm - algorithm = PkgAlgorithmFactory::GetDigestAlgorithm(pkgInfo_.pkgInfo.digestMethod); - PKG_CHECK(algorithm != nullptr, return PKG_NOT_EXIST_ALGORITHM, - "Invalid file %s", pkgStream_->GetFileName().c_str()); - algorithm->Init(); algorithm->Update(buffer, currLen); // Generate digest return PKG_SUCCESS; }