Skip to content

Commit a0b88ca

Browse files
authored
fix abort on invalid null value parsing in BinaryJson (#10991)
1 parent 50bb60a commit a0b88ca

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

ydb/library/binary_json/ut/entry_ut.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class TBinaryJsonEntryTest : public TBinaryJsonTestBase {
1717
UNIT_TEST(TestGetContainer);
1818
UNIT_TEST(TestGetString);
1919
UNIT_TEST(TestGetNumber);
20+
UNIT_TEST(TestInvalidInput);
2021
UNIT_TEST_SUITE_END();
2122

2223
void TestGetType() {
@@ -93,6 +94,18 @@ class TBinaryJsonEntryTest : public TBinaryJsonTestBase {
9394
UNIT_ASSERT_VALUES_EQUAL(container.GetElement(0).GetNumber(), testCase.second);
9495
}
9596
}
97+
98+
void TestInvalidInput() {
99+
const TVector<std::pair<TString, TString>> testCases = {
100+
{"nul", "N_ATOM_ERROR: Problem while parsing an atom starting with the letter 'n'"},
101+
};
102+
103+
for (const auto& testCase : testCases) {
104+
const auto parsingResult = SerializeToBinaryJson(testCase.first);
105+
UNIT_ASSERT(parsingResult.IsFail());
106+
UNIT_ASSERT_VALUES_EQUAL(parsingResult.GetErrorMessage(), testCase.second);
107+
}
108+
}
96109
};
97110

98111
UNIT_TEST_SUITE_REGISTRATION(TBinaryJsonEntryTest);

ydb/library/binary_json/write.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,9 @@ template <typename TOnDemandValue>
600600
case simdjson::ondemand::json_type::null: {
601601
auto is_null = value.is_null();
602602
RETURN_IF_NOT_SUCCESS(is_null.error());
603-
Y_ABORT_UNLESS(is_null.value_unsafe());
603+
if (Y_UNLIKELY(!is_null.value_unsafe())) {
604+
return simdjson::error_code::N_ATOM_ERROR;
605+
}
604606
callbacks.OnNull();
605607
break;
606608
}

0 commit comments

Comments
 (0)