Skip to content

YQ RD fixed use after free #10978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions ydb/core/fq/libs/row_dispatcher/json_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class TJsonParser::TImpl {
public:
TImpl(const TVector<TString>& columns, const TVector<TString>& types, ui64 batchSize, TDuration batchCreationTimeout)
: Alloc(__LOCATION__, NKikimr::TAlignedPagePoolCounters(), true, false)
, TypeEnv(Alloc)
, TypeEnv(std::make_unique<NKikimr::NMiniKQL::TTypeEnvironment>(Alloc))
, BatchSize(batchSize)
, BatchCreationTimeout(batchCreationTimeout)
, ParsedValues(columns.size())
Expand All @@ -273,7 +273,7 @@ class TJsonParser::TImpl {

with_lock (Alloc) {
auto functonRegistry = NKikimr::NMiniKQL::CreateFunctionRegistry(&PrintBackTrace, NKikimr::NMiniKQL::CreateBuiltinRegistry(), false, {});
NKikimr::NMiniKQL::TProgramBuilder programBuilder(TypeEnv, *functonRegistry);
NKikimr::NMiniKQL::TProgramBuilder programBuilder(*TypeEnv, *functonRegistry);

Columns.reserve(columns.size());
for (size_t i = 0; i < columns.size(); i++) {
Expand Down Expand Up @@ -370,8 +370,12 @@ class TJsonParser::TImpl {
}

~TImpl() {
Alloc.Acquire();
ClearColumns(0);
with_lock (Alloc) {
ClearColumns(0);
ParsedValues.clear();
Columns.clear();
TypeEnv.reset();
}
}

private:
Expand All @@ -392,7 +396,7 @@ class TJsonParser::TImpl {

private:
NKikimr::NMiniKQL::TScopedAlloc Alloc;
NKikimr::NMiniKQL::TTypeEnvironment TypeEnv;
std::unique_ptr<NKikimr::NMiniKQL::TTypeEnvironment> TypeEnv;

const ui64 BatchSize;
const TDuration BatchCreationTimeout;
Expand All @@ -402,7 +406,7 @@ class TJsonParser::TImpl {
TJsonParserBuffer Buffer;
simdjson::ondemand::parser Parser;

TVector<std::vector<NYql::NUdf::TUnboxedValue, NKikimr::NMiniKQL::TMKQLAllocator<NYql::NUdf::TUnboxedValue>>> ParsedValues;
TVector<NKikimr::NMiniKQL::TUnboxedValueVector> ParsedValues;
};

TJsonParser::TJsonParser(const TVector<TString>& columns, const TVector<TString>& types, ui64 batchSize, TDuration batchCreationTimeout)
Expand Down
11 changes: 11 additions & 0 deletions ydb/core/fq/libs/row_dispatcher/ut/json_parser_ut.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <ydb/core/base/backtrace.h>

#include <ydb/core/fq/libs/ydb/ydb.h>
#include <ydb/core/fq/libs/events/events.h>

Expand All @@ -22,7 +24,16 @@ class TFixture : public NUnitTest::TBaseFixture {
TFixture()
: Runtime(true) {}

static void SegmentationFaultHandler(int) {
Cerr << "segmentation fault call stack:" << Endl;
FormatBackTrace(&Cerr);
abort();
}

void SetUp(NUnitTest::TTestContext&) override {
NKikimr::EnableYDBBacktraceFormat();
signal(SIGSEGV, &SegmentationFaultHandler);

TAutoPtr<TAppPrepare> app = new TAppPrepare();
Runtime.SetLogBackend(CreateStderrBackend());
Runtime.SetLogPriority(NKikimrServices::FQ_ROW_DISPATCHER, NLog::PRI_TRACE);
Expand Down
1 change: 0 additions & 1 deletion ydb/core/fq/libs/row_dispatcher/ut/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ PEERDIR(
ydb/library/yql/udfs/common/yson2
ydb/tests/fq/pq_async_io
ydb/library/yql/sql/pg_dummy
ydb/library/yql/udfs/common/clickhouse/client
)

SIZE(MEDIUM)
Expand Down
Loading