Skip to content

Commit 11838a0

Browse files
authored
YQ RD fixed use after free (#10978)
1 parent aa53d0d commit 11838a0

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

ydb/core/fq/libs/row_dispatcher/json_parser.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class TJsonParser::TImpl {
264264
public:
265265
TImpl(const TVector<TString>& columns, const TVector<TString>& types, ui64 batchSize, TDuration batchCreationTimeout)
266266
: Alloc(__LOCATION__, NKikimr::TAlignedPagePoolCounters(), true, false)
267-
, TypeEnv(Alloc)
267+
, TypeEnv(std::make_unique<NKikimr::NMiniKQL::TTypeEnvironment>(Alloc))
268268
, BatchSize(batchSize)
269269
, BatchCreationTimeout(batchCreationTimeout)
270270
, ParsedValues(columns.size())
@@ -273,7 +273,7 @@ class TJsonParser::TImpl {
273273

274274
with_lock (Alloc) {
275275
auto functonRegistry = NKikimr::NMiniKQL::CreateFunctionRegistry(&PrintBackTrace, NKikimr::NMiniKQL::CreateBuiltinRegistry(), false, {});
276-
NKikimr::NMiniKQL::TProgramBuilder programBuilder(TypeEnv, *functonRegistry);
276+
NKikimr::NMiniKQL::TProgramBuilder programBuilder(*TypeEnv, *functonRegistry);
277277

278278
Columns.reserve(columns.size());
279279
for (size_t i = 0; i < columns.size(); i++) {
@@ -370,8 +370,12 @@ class TJsonParser::TImpl {
370370
}
371371

372372
~TImpl() {
373-
Alloc.Acquire();
374-
ClearColumns(0);
373+
with_lock (Alloc) {
374+
ClearColumns(0);
375+
ParsedValues.clear();
376+
Columns.clear();
377+
TypeEnv.reset();
378+
}
375379
}
376380

377381
private:
@@ -392,7 +396,7 @@ class TJsonParser::TImpl {
392396

393397
private:
394398
NKikimr::NMiniKQL::TScopedAlloc Alloc;
395-
NKikimr::NMiniKQL::TTypeEnvironment TypeEnv;
399+
std::unique_ptr<NKikimr::NMiniKQL::TTypeEnvironment> TypeEnv;
396400

397401
const ui64 BatchSize;
398402
const TDuration BatchCreationTimeout;
@@ -402,7 +406,7 @@ class TJsonParser::TImpl {
402406
TJsonParserBuffer Buffer;
403407
simdjson::ondemand::parser Parser;
404408

405-
TVector<std::vector<NYql::NUdf::TUnboxedValue, NKikimr::NMiniKQL::TMKQLAllocator<NYql::NUdf::TUnboxedValue>>> ParsedValues;
409+
TVector<NKikimr::NMiniKQL::TUnboxedValueVector> ParsedValues;
406410
};
407411

408412
TJsonParser::TJsonParser(const TVector<TString>& columns, const TVector<TString>& types, ui64 batchSize, TDuration batchCreationTimeout)

ydb/core/fq/libs/row_dispatcher/ut/json_parser_ut.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <ydb/core/base/backtrace.h>
2+
13
#include <ydb/core/fq/libs/ydb/ydb.h>
24
#include <ydb/core/fq/libs/events/events.h>
35

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

27+
static void SegmentationFaultHandler(int) {
28+
Cerr << "segmentation fault call stack:" << Endl;
29+
FormatBackTrace(&Cerr);
30+
abort();
31+
}
32+
2533
void SetUp(NUnitTest::TTestContext&) override {
34+
NKikimr::EnableYDBBacktraceFormat();
35+
signal(SIGSEGV, &SegmentationFaultHandler);
36+
2637
TAutoPtr<TAppPrepare> app = new TAppPrepare();
2738
Runtime.SetLogBackend(CreateStderrBackend());
2839
Runtime.SetLogPriority(NKikimrServices::FQ_ROW_DISPATCHER, NLog::PRI_TRACE);

ydb/core/fq/libs/row_dispatcher/ut/ya.make

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ PEERDIR(
2020
ydb/library/yql/udfs/common/yson2
2121
ydb/tests/fq/pq_async_io
2222
ydb/library/yql/sql/pg_dummy
23-
ydb/library/yql/udfs/common/clickhouse/client
2423
)
2524

2625
SIZE(MEDIUM)

0 commit comments

Comments
 (0)