Skip to content
Open
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
17 changes: 17 additions & 0 deletions cpp/src/arrow/engine/substrait/serde_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include "arrow/type.h"
#include "arrow/type_fwd.h"
#include "arrow/util/async_generator_fwd.h"
#include "arrow/util/base64.h"
#include "arrow/util/checked_cast.h"
#include "arrow/util/config.h"
#include "arrow/util/decimal.h"
Expand Down Expand Up @@ -1581,6 +1582,22 @@ TEST(Substrait, InvalidEmptyExtensionDeclaration) {
ASSERT_RAISES(Invalid, DeserializePlans(*buf, [] { return kNullConsumer; }));
}

TEST(Substrait, InvalidDecimalPrecisionReturnsStatus) {
// GH-50230: a decimal precision outside [1, 38] must produce an error rather
// than aborting the process in the Decimal128Type constructor.
constexpr std::string_view kPocBase64 =
"GswBCskBCsYBEr4BCgJjMAoCYzEKAmMyCgJjMwoCYzQKAmM1CgJjNgoCYzcKAmM4CgJjOQoDYzEw"
"CgNjMTEKA2MxMgoDYzEzCgNjMTQKA2MxNQoDYzE2CgNjMTcSbAoCCgAKAhIACgIaAAoCKgAKAjoA"
"CgJSAAoCWgAKAmIACgJqAAoCcgAKA4IBAAoDigEACgfCAQQIAhAqCgWqAQIIBAoFsgECCAgKB9oB"
"BAoCOgAKC+IBCAoCYgASAjoACgvKAQgKAioACgJiADoDCgF0MgsQLCoHbzItc2VlZA==";
ASSERT_OK_AND_ASSIGN(auto poc, util::base64_decode(kPocBase64));
ASSERT_EQ(poc.size(), 220);

EXPECT_THAT(DeserializePlan(*Buffer::FromString(std::move(poc)),
/*registry=*/nullptr, /*ext_set_out=*/nullptr),
Raises(StatusCode::Invalid, HasSubstr("Decimal precision out of range")));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do a "classic" boundary check tests with 0, 1, 38, or 39, please?

}

TEST(Substrait, JoinPlanBasic) {
std::string substrait_json = R"({
"version": { "major_number": 9999, "minor_number": 9999, "patch_number": 9999 },
Expand Down
4 changes: 3 additions & 1 deletion cpp/src/arrow/engine/substrait/type_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ Result<std::pair<std::shared_ptr<DataType>, bool>> FromProto(

case substrait::Type::kDecimal: {
const auto& decimal = type.decimal();
return FromProtoImpl<Decimal128Type>(decimal, decimal.precision(), decimal.scale());
ARROW_ASSIGN_OR_RAISE(auto decimal_type,
Decimal128Type::Make(decimal.precision(), decimal.scale()));
return std::make_pair(std::move(decimal_type), IsNullable(decimal));
}

case substrait::Type::kStruct: {
Expand Down
Loading