diff --git a/services/diffpatch/diff/blocks_diff.cpp b/services/diffpatch/diff/blocks_diff.cpp index 29d4fab20eb42018e07e29f4166330212d207009..8396667f0f31031e77ffec6a8bb868ddcf7150c7 100644 --- a/services/diffpatch/diff/blocks_diff.cpp +++ b/services/diffpatch/diff/blocks_diff.cpp @@ -34,6 +34,7 @@ constexpr uint32_t BUCKET_SIZE = 256; constexpr uint32_t MULTIPLE_TWO = 2; constexpr int64_t BLOCK_SCORE = 8; constexpr int64_t MIN_LENGTH = 16; +constexpr uint32_t MAX_PATCH_LENGTH = 1024 * 1024 * 1024; // 1G static void WriteLE64(const BlockBuffer &buffer, int64_t value) { @@ -79,6 +80,10 @@ int32_t BlocksDiff::MakePatch(const std::string &oldFileName, const std::string } BlockBuffer newInfo = {newBuffer.memory, newBuffer.length}; BlockBuffer oldInfo = {oldBuffer.memory, oldBuffer.length}; + if (oldInfo.length > MAX_PATCH_LENGTH) { + PATCH_LOGE("length is illegal, current length is %zu", oldInfo.length); + return -1; + } std::unique_ptr blockdiff = std::make_unique(patchFile, 0); size_t patchSize = 0; ret = blockdiff->MakePatch(newInfo, oldInfo, patchSize); diff --git a/services/fs_manager/do_partition.cpp b/services/fs_manager/do_partition.cpp index 97e19b66a5252c2f189b5d328e0323dc6a001209..a81d37b7e9f2fdb821cb7d6256186ef055132732 100644 --- a/services/fs_manager/do_partition.cpp +++ b/services/fs_manager/do_partition.cpp @@ -192,13 +192,15 @@ static void DestroyDiskPartitions(Disk &disk) disk.partList.clear(); } -static void DestroyDiskDevices(const Disk &disk) +static void DestroyDiskDevices(Disk &disk) { if (disk.dev != nullptr) { if (disk.dev->specific != nullptr) { free(disk.dev->specific); + disk.dev->specific = nullptr; } free(disk.dev); + disk.dev = nullptr; } }