From ddec38064447aac01606e012a40156bc00c8f8b5 Mon Sep 17 00:00:00 2001 From: ColinLee Date: Sun, 29 Nov 2026 23:45:21 +0800 Subject: [PATCH 1/2] ci: keep CodeQL scans on first-party sources The C/C++ autobuild unpacks third-party dependencies under cpp/_codeql_build_dir and compiles them as part of the analysis. The quality scan reported about 560 alerts against those sources. The paths-ignore entry named the directory without a glob, which does not match a subtree, so the filter never took effect and the first scheduled run already produced the alerts it was meant to prevent. Match the directory with a ** glob, ignore the gitignored cpp/third_party build extracts as well, and share the configuration with the security scan, which had no config file and therefore analyzed the build directory too. --- .../{codeql-quality-config.yml => codeql-config.yml} | 10 +++++++--- .github/workflows/codeql-quality.yml | 2 +- .github/workflows/codeql.yml | 3 +++ 3 files changed, 11 insertions(+), 4 deletions(-) rename .github/codeql/{codeql-quality-config.yml => codeql-config.yml} (66%) diff --git a/.github/codeql/codeql-quality-config.yml b/.github/codeql/codeql-config.yml similarity index 66% rename from .github/codeql/codeql-quality-config.yml rename to .github/codeql/codeql-config.yml index 975d6df9b..135856275 100644 --- a/.github/codeql/codeql-quality-config.yml +++ b/.github/codeql/codeql-config.yml @@ -15,8 +15,12 @@ # specific language governing permissions and limitations # under the License. -name: "CodeQL quality configuration" +name: "CodeQL configuration" paths-ignore: - # Third-party dependencies fetched by the C++ build, not our code. - - cpp/_codeql_build_dir + # CodeQL's C/C++ autobuild unpacks third-party dependencies here and compiles + # them as part of the analysis; they are not part of the TsFile source tree. + # The glob must end in /** — a bare directory name does not match a subtree. + - '**/_codeql_build_dir/**' + # Build-managed third-party sources extracted by the C++ build (gitignored). + - 'cpp/third_party/**' diff --git a/.github/workflows/codeql-quality.yml b/.github/workflows/codeql-quality.yml index dd2f7db4a..4cbfd40d1 100644 --- a/.github/workflows/codeql-quality.yml +++ b/.github/workflows/codeql-quality.yml @@ -58,7 +58,7 @@ jobs: with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} - config-file: ./.github/codeql/codeql-quality-config.yml + config-file: ./.github/codeql/codeql-config.yml # Superset of the default suite: also runs maintainability/reliability queries. queries: security-and-quality diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index cb96c0658..5b29c1cb4 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -121,6 +121,9 @@ jobs: with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} + # Shares the path exclusions with the quality scan: the C++ autobuild + # compiles third-party dependencies under cpp/_codeql_build_dir. + config-file: ./.github/codeql/codeql-config.yml - name: Build Go for CodeQL if: matrix.language == 'go' && matrix.build-mode == 'manual' working-directory: go From 94da434ea99a936a1b6b64fce5fd2d9710c0730a Mon Sep 17 00:00:00 2001 From: ColinLee Date: Sun, 29 Nov 2026 23:45:24 +0800 Subject: [PATCH 2/2] fix(cpp): resolve CodeQL findings in the reader and writer - Give ITimeseriesIndex a virtual destructor; it is held through shared_ptr and destroyed through the base type. - Qualify the reset() call in the TS2DIFFDecoder constructor so it does not dispatch to a derived override while the base is still being constructed. - Release SeriesScanStream's column iterator from its destructor instead of relying on the owner to call destroy(). - Use localtime_r/localtime_s in DaysSinceEpochToYYYYMMDD. localtime returns a shared buffer and its result was dereferenced unchecked. - Drop the int32 range check in date_to_int: year is bounded to 1000..9999, so the packed value cannot overflow. - Allocate the aligned ValueChunkWriter with std::nothrow so the following null check can actually fail instead of being dead code. --- cpp/src/common/datatype/date_converter.h | 12 +++++------- cpp/src/common/tsfile_common.h | 2 +- cpp/src/encoding/ts2diff_decoder.h | 4 +++- cpp/src/reader/qds_with_timegenerator.h | 1 + cpp/src/utils/date_utils.h | 14 ++++++++++++-- cpp/src/writer/tsfile_writer.cc | 3 ++- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/cpp/src/common/datatype/date_converter.h b/cpp/src/common/datatype/date_converter.h index 82d76441f..1d8ea8b3f 100644 --- a/cpp/src/common/datatype/date_converter.h +++ b/cpp/src/common/datatype/date_converter.h @@ -56,13 +56,11 @@ class DateConverter { return E_INVALID_ARG; } - const int64_t result = - static_cast(year) * 10000 + month * 100 + day; - if (result > INT32_MAX || result < INT32_MIN) { - return E_OUT_OF_RANGE; - } - - out_int = static_cast(result); + // year is bounded to 1000..9999 above, so the packed value stays + // within int32 range. + const int32_t result = + static_cast(year * 10000 + month * 100 + day); + out_int = result; return E_OK; } diff --git a/cpp/src/common/tsfile_common.h b/cpp/src/common/tsfile_common.h index 49b54603d..56c1593b2 100644 --- a/cpp/src/common/tsfile_common.h +++ b/cpp/src/common/tsfile_common.h @@ -314,7 +314,7 @@ struct ChunkGroupMeta { class ITimeseriesIndex { public: ITimeseriesIndex() {} - ~ITimeseriesIndex() {} + virtual ~ITimeseriesIndex() = default; virtual common::SimpleList* get_chunk_meta_list() const { return nullptr; } diff --git a/cpp/src/encoding/ts2diff_decoder.h b/cpp/src/encoding/ts2diff_decoder.h index 721656b9c..5fa1b62bd 100644 --- a/cpp/src/encoding/ts2diff_decoder.h +++ b/cpp/src/encoding/ts2diff_decoder.h @@ -318,7 +318,9 @@ inline int read_page_meta(common::ByteStream& in, PageMeta& meta) { template class TS2DIFFDecoder : public Decoder { public: - TS2DIFFDecoder() { reset(); } + // Qualified on purpose: a derived decoder is not constructed yet, so the + // base-state reset must not dispatch to the derived override. + TS2DIFFDecoder() { TS2DIFFDecoder::reset(); } ~TS2DIFFDecoder() override {} void reset() override { diff --git a/cpp/src/reader/qds_with_timegenerator.h b/cpp/src/reader/qds_with_timegenerator.h index 52892df14..e8d55803c 100644 --- a/cpp/src/reader/qds_with_timegenerator.h +++ b/cpp/src/reader/qds_with_timegenerator.h @@ -43,6 +43,7 @@ struct SeriesScanStream { ssi_(nullptr), tsblock_(nullptr), col_iter_(nullptr) {} + ~SeriesScanStream() { destroy(); } int init(); void destroy(); int64_t front(); diff --git a/cpp/src/utils/date_utils.h b/cpp/src/utils/date_utils.h index 77323812e..b65e254f9 100644 --- a/cpp/src/utils/date_utils.h +++ b/cpp/src/utils/date_utils.h @@ -60,8 +60,18 @@ inline int32_t DaysSinceEpochToYYYYMMDD(int32_t days) { epoch.tm_isdst = -1; time_t epoch_t = mktime(&epoch); time_t target_t = epoch_t + static_cast(days) * 24 * 60 * 60; - std::tm* d = localtime(&target_t); - return (d->tm_year + 1900) * 10000 + (d->tm_mon + 1) * 100 + d->tm_mday; + std::tm target = {}; +#ifdef _WIN32 + if (localtime_s(&target, &target_t) != 0) { + return 0; + } +#else + if (localtime_r(&target_t, &target) == nullptr) { + return 0; + } +#endif + return (target.tm_year + 1900) * 10000 + (target.tm_mon + 1) * 100 + + target.tm_mday; } } // namespace common diff --git a/cpp/src/writer/tsfile_writer.cc b/cpp/src/writer/tsfile_writer.cc index 13585d066..4b8f8a311 100644 --- a/cpp/src/writer/tsfile_writer.cc +++ b/cpp/src/writer/tsfile_writer.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "chunk_writer.h" @@ -602,7 +603,7 @@ int TsFileWriter::ensure_aligned_value_chunk_writer( if (measurement_schema->value_chunk_writer_ != nullptr) { return E_OK; } - ValueChunkWriter* value_chunk_writer = new ValueChunkWriter; + ValueChunkWriter* value_chunk_writer = new (std::nothrow) ValueChunkWriter; if (IS_NULL(value_chunk_writer)) { return E_OOM; }