Skip to content

Commit

Permalink
fix abort on invalid null value parsing in BinaryJson (ydb-platform#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
swalrus1 authored and zverevgeny committed Jan 1, 2025
1 parent abefcc9 commit 717ffdc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions ydb/library/binary_json/ut/entry_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class TBinaryJsonEntryTest : public TBinaryJsonTestBase {
UNIT_TEST(TestGetContainer);
UNIT_TEST(TestGetString);
UNIT_TEST(TestGetNumber);
UNIT_TEST(TestInvalidInput);
UNIT_TEST_SUITE_END();

void TestGetType() {
Expand Down Expand Up @@ -93,6 +94,18 @@ class TBinaryJsonEntryTest : public TBinaryJsonTestBase {
UNIT_ASSERT_VALUES_EQUAL(container.GetElement(0).GetNumber(), testCase.second);
}
}

void TestInvalidInput() {
const TVector<std::pair<TString, TString>> testCases = {
{"nul", "N_ATOM_ERROR: Problem while parsing an atom starting with the letter 'n'"},
};

for (const auto& testCase : testCases) {
const auto parsingResult = SerializeToBinaryJson(testCase.first);
UNIT_ASSERT(parsingResult.IsFail());
UNIT_ASSERT_VALUES_EQUAL(parsingResult.GetErrorMessage(), testCase.second);
}
}
};

UNIT_TEST_SUITE_REGISTRATION(TBinaryJsonEntryTest);
4 changes: 3 additions & 1 deletion ydb/library/binary_json/write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,9 @@ template <typename TOnDemandValue>
case simdjson::ondemand::json_type::null: {
auto is_null = value.is_null();
RETURN_IF_NOT_SUCCESS(is_null.error());
Y_ABORT_UNLESS(is_null.value_unsafe());
if (Y_UNLIKELY(!is_null.value_unsafe())) {
return simdjson::error_code::N_ATOM_ERROR;
}
callbacks.OnNull();
break;
}
Expand Down

0 comments on commit 717ffdc

Please sign in to comment.