diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2023-11-24 09:29:07 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2023-11-24 09:45:07 +0300 |
commit | 61d380beacde734e41d65d5404742fccc9f6f4b3 (patch) | |
tree | 8aafc4c13a73e77cf68145f6438f87c470cb33b3 /contrib | |
parent | 778162c87fe52768297a4e767461054aa9c94dfe (diff) | |
download | ydb-61d380beacde734e41d65d5404742fccc9f6f4b3.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/clickhouse/src/Compression/CompressionCodecGorilla.cpp | 19 | ||||
-rw-r--r-- | contrib/clickhouse/src/Storages/StorageMaterializedView.cpp | 8 |
2 files changed, 21 insertions, 6 deletions
diff --git a/contrib/clickhouse/src/Compression/CompressionCodecGorilla.cpp b/contrib/clickhouse/src/Compression/CompressionCodecGorilla.cpp index aca68fab9a..1b2fbbbb22 100644 --- a/contrib/clickhouse/src/Compression/CompressionCodecGorilla.cpp +++ b/contrib/clickhouse/src/Compression/CompressionCodecGorilla.cpp @@ -264,7 +264,7 @@ UInt32 compressDataForType(const char * source, UInt32 source_size, char * dest, } template <typename T> -void decompressDataForType(const char * source, UInt32 source_size, char * dest) +void decompressDataForType(const char * source, UInt32 source_size, char * dest, UInt32 dest_size) { const char * const source_end = source + source_size; @@ -280,6 +280,9 @@ void decompressDataForType(const char * source, UInt32 source_size, char * dest) if (source + sizeof(T) > source_end || items_count < 1) return; + if (static_cast<UInt64>(items_count) * sizeof(T) > dest_size) + throw Exception(ErrorCodes::CANNOT_DECOMPRESS, "Cannot decompress Gorilla-encoded data: corrupted input data."); + prev_value = unalignedLoadLittleEndian<T>(source); unalignedStoreLittleEndian<T>(dest, prev_value); @@ -422,22 +425,28 @@ void CompressionCodecGorilla::doDecompressData(const char * source, UInt32 sourc if (static_cast<UInt32>(2 + bytes_to_skip) > source_size) throw Exception(ErrorCodes::CANNOT_DECOMPRESS, "Cannot decompress. File has wrong header"); + if (bytes_to_skip >= uncompressed_size) + throw Exception(ErrorCodes::CANNOT_DECOMPRESS, "Cannot decompress Gorilla-encoded data. File has wrong header"); + memcpy(dest, &source[2], bytes_to_skip); UInt32 source_size_no_header = source_size - bytes_to_skip - 2; + UInt32 uncompressed_size_left = uncompressed_size - bytes_to_skip; switch (bytes_size) { case 1: - decompressDataForType<UInt8>(&source[2 + bytes_to_skip], source_size_no_header, &dest[bytes_to_skip]); + decompressDataForType<UInt8>(&source[2 + bytes_to_skip], source_size_no_header, &dest[bytes_to_skip], uncompressed_size_left); break; case 2: - decompressDataForType<UInt16>(&source[2 + bytes_to_skip], source_size_no_header, &dest[bytes_to_skip]); + decompressDataForType<UInt16>(&source[2 + bytes_to_skip], source_size_no_header, &dest[bytes_to_skip], uncompressed_size_left); break; case 4: - decompressDataForType<UInt32>(&source[2 + bytes_to_skip], source_size_no_header, &dest[bytes_to_skip]); + decompressDataForType<UInt32>(&source[2 + bytes_to_skip], source_size_no_header, &dest[bytes_to_skip], uncompressed_size_left); break; case 8: - decompressDataForType<UInt64>(&source[2 + bytes_to_skip], source_size_no_header, &dest[bytes_to_skip]); + decompressDataForType<UInt64>(&source[2 + bytes_to_skip], source_size_no_header, &dest[bytes_to_skip], uncompressed_size_left); break; + default: + throw Exception(ErrorCodes::CANNOT_DECOMPRESS, "Cannot decompress Gorilla-encoded data. File has wrong header"); } } diff --git a/contrib/clickhouse/src/Storages/StorageMaterializedView.cpp b/contrib/clickhouse/src/Storages/StorageMaterializedView.cpp index 7354dd5655..139819144f 100644 --- a/contrib/clickhouse/src/Storages/StorageMaterializedView.cpp +++ b/contrib/clickhouse/src/Storages/StorageMaterializedView.cpp @@ -431,7 +431,13 @@ void StorageMaterializedView::backupData(BackupEntriesCollector & backup_entries { /// We backup the target table's data only if it's inner. if (hasInnerTable()) - getTargetTable()->backupData(backup_entries_collector, data_path_in_backup, partitions); + { + if (auto table = tryGetTargetTable()) + table->backupData(backup_entries_collector, data_path_in_backup, partitions); + else + LOG_WARNING(&Poco::Logger::get("StorageMaterializedView"), + "Inner table does not exist, will not backup any data"); + } } void StorageMaterializedView::restoreDataFromBackup(RestorerFromBackup & restorer, const String & data_path_in_backup, const std::optional<ASTs> & partitions) |